Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'format' in message.py in 2.5.0 #3564

Closed
rrauenza opened this issue May 1, 2020 · 4 comments · Fixed by #3699
Closed
Assignees
Labels
Milestone

Comments

@rrauenza
Copy link

rrauenza commented May 1, 2020

I have a cicd that suddenly started failing because tox started bringing in pylint 2.5.0 (I've now pinned it to < 2.5.0).

I can't share the source code externally so I'll do my best to see if I can track this down just from the stack trace. I apologize I can't provide steps to reproduce -- I hope this stack trace and the template value being None is enough to track down the cause.

Traceback (most recent call last):
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/run.py", line 338, in __init__
    linter.check(args)
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 878, in check
    files_or_modules,
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/check_parallel.py", line 106, in check_parallel
    linter.reporter.handle_message(msg)
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/reporters/text.py", line 151, in handle_message
    self.write_message(msg)
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/reporters/text.py", line 141, in write_message
    self.writeln(msg.format(self._template))
  File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/message/message.py", line 51, in format
    return template.format(**dict(zip(self._fields, self)))
AttributeError: 'NoneType' object has no attribute 'format'
ERROR: InvocationError for command /opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/bin/pylint src/ (exited with code 1)

It looks like in message.py, template is None.

In the TextReporter class in text.py, self._template is initialized to be None by the class and not changed, so is passed down to message.py

My pylintrc:

[MASTER]
extension-pkg-whitelist=
ignore=CVS
ignore-patterns=
jobs=0
limit-inference-results=100
load-plugins=
persistent=yes
suggestion-mode=yes
unsafe-load-any-extension=no
[MESSAGES CONTROL]
confidence=
enable=c-extension-no-member
[REPORTS]
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
output-format=text
reports=no
score=yes
[REFACTORING]
max-nested-blocks=5
never-returning-functions=sys.exit
[BASIC]
argument-naming-style=snake_case
argument-rgx=^[a-z][a-z0-9]*((_[a-z0-9]+)*)?$
attr-naming-style=snake_case
bad-names=foo,
          bar,
          baz,
class-attribute-naming-style=any
class-naming-style=PascalCase
const-naming-style=UPPER_CASE
docstring-min-length=-1
function-naming-style=snake_case
good-names=_
include-naming-hint=no
inlinevar-naming-style=any
method-naming-style=snake_case
module-naming-style=snake_case
name-group=
no-docstring-rgx=^_
property-classes=abc.abstractproperty
variable-naming-style=snake_case
[FORMAT]
expected-line-ending-format=
indent-after-paren=4
indent-string='    '
max-line-length=90
max-module-lines=1000
no-space-check=trailing-comma,
               dict-separator
single-line-class-stmt=no
single-line-if-stmt=no
[LOGGING]
logging-format-style=old
logging-modules=logging
[MISCELLANEOUS]
notes=FIXME,
      XXX,
      TODO
[SIMILARITIES]
ignore-comments=yes
ignore-docstrings=yes
ignore-imports=no
min-similarity-lines=4
[SPELLING]
max-spelling-suggestions=4
spelling-dict=
spelling-ignore-words=
spelling-private-dict-file=
spelling-store-unknown-words=no
[STRING]
check-str-concat-over-line-jumps=no
[TYPECHECK]
contextmanager-decorators=contextlib.contextmanager
generated-members=
ignore-mixin-members=yes
ignore-none=yes
ignore-on-opaque-inference=yes
ignored-classes=optparse.Values,thread._local,_thread._local
ignored-modules=
missing-member-hint=yes
missing-member-hint-distance=1
missing-member-max-choices=1
signature-mutators=
[VARIABLES]
additional-builtins=
allow-global-unused-variables=yes
callbacks=cb_,
          _cb
ignored-argument-names=^_$
init-import=no
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
[CLASSES]
defining-attr-methods=__init__,
                      __new__,
                      setUp,
                      __post_init__
exclude-protected=_asdict,
                  _fields,
                  _replace,
                  _source,
                  _make
valid-classmethod-first-arg=cls
valid-metaclass-classmethod-first-arg=cls
[DESIGN]
max-args=10
max-attributes=10
max-bool-expr=5
max-branches=12
max-locals=20
max-parents=20
max-public-methods=20
max-returns=6
max-statements=50
min-public-methods=2
[IMPORTS]
allow-any-import-level=
allow-wildcard-with-all=no
analyse-fallback-blocks=no
deprecated-modules=optparse,tkinter.tix
ext-import-graph=
import-graph=
int-import-graph=
known-standard-library=
known-third-party=enchant
preferred-modules=
[EXCEPTIONS]
overgeneral-exceptions=BaseException,
                       Exception
@rrauenza
Copy link
Author

rrauenza commented May 1, 2020

I set a breakpoint in

      def on_set_current_module(self, module, filepath):                                             
          import pdb; pdb.set_trace()                                                       
          self._template = str(self.linter.config.msg_template or self.line_format)  

And it never gets called. I tried setting a breakpoint in set_current_module in pylinter.py, but pylint doesn't seem to let me break there -- stdin is gone or something. But printing out modname and filepath,

$ .tox/pylint/bin/pylint src/
modname: 
filepath: src/__init__.py
modname: 
filepath: None

Under src/ I have,

$ ll src/
total 12
drwxr-xr-x 10 rich mts 4096 Mar 17 15:38 projectname
drwxr-xr-x  2 rich mts  128 Nov 15 16:31 projectname.egg-info
drwxr-xr-x  5 rich mts 4096 Mar  3 13:20 tests
-rwxr--r--  1 rich mts  445 Nov 15 08:03 unittests 

@PCManticore
Copy link
Contributor

Hey @rrauenza I'm afraid I can't reproduce it. How did you run pylint over your project?

Also if you set up a breakpoint in check_parallel.py at line 103 where it's linter.set_current_module(module), can you verify what the value of module is?
You might have to run this with a single job (e.g. with -j1) to not have any issues with the debugger's input in a multi-threaded situation.

@PCManticore PCManticore added the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label May 2, 2020
@rrauenza
Copy link
Author

rrauenza commented May 4, 2020

It looks like it is an empty string (there's some more debug output I also added):

$ ./.tox/pylint/bin/pylint src/
modname: 
filepath: src/__init__.py
**** module: ''/<class 'str'>
modname: 
filepath: None
************* 

src/__init__.py doesn't exist, btw.

Where the other output was added:

def set_current_module(self, modname, filepath=None):
        """set the name of the currently analyzed module and
        init statistics for it
        """
        print("modname: %s" % modname)
        print("filepath: %s" % filepath)

@rrauenza
Copy link
Author

rrauenza commented May 4, 2020

aha -- I got a test case. I had to add chicken (directory):

$ find baked/
baked/
baked/beans
baked/beans/__init__.py
baked/chicken
$ .tox/pylint/bin/pylint baked/
modname: 
filepath: baked/__init__.py
***** module: ''/<class 'str'>
modname: 
filepath: None
************* 
[...]
AttributeError: 'NoneType' object has no attribute 'format'

Argh, but now it does it without chicken, too, and I'd swear it didn't earlier:

$ rmdir baked/chicken/

$ .tox/pylint/bin/pylint baked/
AttributeError: 'NoneType' object has no attribute 'format'

I wonder if it depends on the order of the subdirectories read.

$ mkdir canned
$ mkdir canned/beans
$ touch canned/beans/__init__.py
$ .tox/pylint/bin/pylint canned/
modname: 
filepath: canned/__init__.py
***** module: ''/<class 'str'>
modname: 
filepath: None
************* 
[...]
AttributeError: 'NoneType' object has no attribute 'format'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants