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

Traceback on unknown encoding #3860

Closed
jwilk opened this issue Sep 24, 2020 · 2 comments · Fixed by #7097
Closed

Traceback on unknown encoding #3860

jwilk opened this issue Sep 24, 2020 · 2 comments · Fixed by #7097
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@jwilk
Copy link
Contributor

jwilk commented Sep 24, 2020

Steps to reproduce

Run Pylint against the following code:

# encoding=UTF-9

Current behavior

Traceback (most recent call last):
  File "/usr/lib/python3.7/tokenize.py", line 397, in find_cookie
    codec = lookup(encoding)
LookupError: unknown encoding: UTF-9

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jwilk/.local/bin/pylint", line 10, in <module>
    sys.exit(run_pylint())
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/lint/run.py", line 349, in __init__
    linter.check(args)
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 863, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 895, in _check_files
    for name, filepath, modname in file_descrs:
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 952, in _iterate_file_descrs
    for descr in self._expand_files(files_or_modules):
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 961, in _expand_files
    modules, self.config.black_list, self.config.black_list_re
  File "/home/jwilk/.local/lib/python3.7/site-packages/pylint/utils/utils.py", line 187, in expand_modules
    modparts, path=additional_search_path
  File "/home/jwilk/.local/lib/python3.7/site-packages/astroid/modutils.py", line 423, in file_info_from_modpath
    return _spec_from_modpath(modpath, path, context)
  File "/home/jwilk/.local/lib/python3.7/site-packages/astroid/modutils.py", line 648, in _spec_from_modpath
    found_spec = spec.find_spec(modpath, path)
  File "/home/jwilk/.local/lib/python3.7/site-packages/astroid/interpreter/_import/spec.py", line 337, in find_spec
    _path, modname, module_parts, processed, submodule_path or path
  File "/home/jwilk/.local/lib/python3.7/site-packages/astroid/interpreter/_import/spec.py", line 300, in _find_spec_with_path
    spec = finder.find_module(modname, module_parts, processed, submodule_path)
  File "/home/jwilk/.local/lib/python3.7/site-packages/astroid/interpreter/_import/spec.py", line 124, in find_module
    stream, mp_filename, mp_desc = imp.find_module(modname, submodule_path)
  File "/usr/lib/python3.7/imp.py", line 301, in find_module
    encoding = tokenize.detect_encoding(file.readline)[0]
  File "/usr/lib/python3.7/tokenize.py", line 426, in detect_encoding
    encoding = find_cookie(first)
  File "/usr/lib/python3.7/tokenize.py", line 405, in find_cookie
    raise SyntaxError(msg)
SyntaxError: unknown encoding for './test.py': UTF-9

Expected behavior

test.py:1:3: E0001: unknown encoding: UTF-9 (<unknown>, line 1) (syntax-error)

(or something similar)

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0]
@hippo91
Copy link
Contributor

hippo91 commented Oct 3, 2020

@jwilk thanks for the report.
This bug is triggered in the imp module that astroid uses.
To be honest i don't think it worth developing a fix inside astroid to solve this kind of issue that is rare and quite easy to avoid.
@AWhetter @Pierre-Sassoulas @PCManticore what do you think about it?

@Pierre-Sassoulas
Copy link
Member

This is strange, we have a functional test with a bogus encoding already (https://github.com/PyCQA/pylint/blob/master/tests/functional/u/unknown_encoding_py29.py) so this should not be happening (?)

@hippo91 hippo91 added Bug 🪲 Minor 💅 Polishing pylint is always nice Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Nov 24, 2020
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 Minor 💅 Polishing pylint is always nice Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Jun 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jun 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.5 milestone Jun 30, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 30, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jun 30, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 9, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 9, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 13, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.14.5, 2.15.0 Jul 17, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants