Skip to content

Error in Pyflakes plugin: 'NoneType' has no len() #429

@elelay

Description

@elelay

Given the file XML.props containing

# :mode=properties:folding=explicit:encoding=Native2Ascii:

Following exceptions occurs:

  File "/usr/lib/python3.11/site-packages/pyflakes/api.py", line 39, in check
    tree = ast.parse(codeString, filename=filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/elelay/jedit/XMLGit/XML.props", line 0
SyntaxError: unknown encoding: Native2Ascii

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 33, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 418, in traced_hookexec
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 108, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 70, in from_call
    result = func()
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 415, in <lambda>
    lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 116, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 80, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pyflakes_lint.py", line 26, in pylsp_lint
    pyflakes_api.check(document.source.encode('utf-8'), document.path, reporter=reporter)
  File "/usr/lib/python3.11/site-packages/pyflakes/api.py", line 41, in check
    reporter.syntaxError(filename, e.args[0], e.lineno, e.offset, e.text)
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pyflakes_lint.py", line 55, in syntaxError
    'end': {'line': lineno - 1, 'character': offset + len(text)},
                                                      ^^^^^^^^^
TypeError: object of type 'NoneType' has no len()

The second one should be avoided by checking in syntaxError that text is not None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions