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

Formatting with yapf failed if module file name is 'token.py' #706

Closed
Tiscs opened this issue Feb 5, 2018 · 4 comments
Closed

Formatting with yapf failed if module file name is 'token.py' #706

Tiscs opened this issue Feb 5, 2018 · 4 comments
Assignees
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug

Comments

@Tiscs
Copy link

Tiscs commented Feb 5, 2018

Environment data

VS Code version: 1.19.3
Python Extension version: 2018.1.0
Python Version: 3.6.4
OS and version: macOS 10.13.3

Actual behavior

Format module failed when file name is token.py.

Expected behavior

The file will be formatted, no errors in output.

Steps to reproduce:

  • Create a file named token.py;
  • Execute command Format Document in vscode;

Logs

Output from Python output panel

Formatting with yapf failed.
Error: Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.6/site-packages/yapf/__init__.py", line 31, in <module>
    import logging
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 26, in <module>
    import sys, os, time, io, traceback, warnings, weakref, collections
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tokenize.py", line 35, in <module>
    from token import *
  File "/Users/Tiscs/Projects/auth.py/config/token.py", line 1, in <module>
    from logging import getLogger
ImportError: cannot import name 'getLogger'

Output from Console window (Help->Developer Tools menu)

Nothing
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug awaiting 1-verification area-formatting labels Feb 5, 2018
@MikhailArkhipov MikhailArkhipov self-assigned this Feb 5, 2018
@MikhailArkhipov
Copy link

This does not seem to be specific to the file name. I get different error

Formatting with yapf failed.
Error: Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yapf/__init__.py", line 31, in <module>
    import logging
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 26, in <module>
    import sys, os, time, io, traceback, warnings, weakref, collections
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/traceback.py", line 5, in <module>
    import linecache
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/linecache.py", line 11, in <module>
    import tokenize
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tokenize.py", line 41, in <module>
    __all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
AttributeError: module 'token' has no attribute '__all__'

autopep8 works fine

@MikhailArkhipov
Copy link

This seems to only repro in Python 3.

google/yapf#403

Comment says yapf really doesn't support python 3 fully, just what lib2to3 can handle

@Tiscs
Copy link
Author

Tiscs commented Feb 11, 2018

Works fine when the module renamed to token_.py.

@DonJayamanne
Copy link

DonJayamanne commented Feb 11, 2018

Probably an issue with the reserved word. Closing the issue.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants