You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extension version (available under the Extensions sidebar): 2018.4.0
OS and version: Windows 10, v.1803
Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.5 (Anaconda, conda 4.5.1)
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
Relevant/affected Python packages and their versions: yapf 0.21.0 (also 0.20.2)
Actual behavior
Format module failed when file name is locale.py.
Expected behavior
The file will be formatted, no errors in output.
Steps to reproduce:
Make a file called locale.py
Try to format it with yapf, in VS Code.
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Traceback (most recent call last):
File "C:\Users\user\Miniconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\user\Miniconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python\VirtualEnv\myproject\lib\site-packages\yapf\__main__.py", line 18, in <module>
yapf.run_main()
File "C:\Python\VirtualEnv\myproject\lib\site-packages\yapf\__init__.py", line 312, in run_main
sys.exit(main(sys.argv))
File "C:\Python\VirtualEnv\myproject\lib\site-packages\yapf\__init__.py", line 57, in main
parser = argparse.ArgumentParser(description='Formatter for Python code.')
File "C:\Users\user\Miniconda3\lib\argparse.py", line 1633, in __init__
self._positionals = add_group(_('positional arguments'))
File "C:\Users\user\Miniconda3\lib\gettext.py", line 612, in gettext
return dgettext(_current_domain, message)
File "C:\Users\user\Miniconda3\lib\gettext.py", line 575, in dgettext
codeset=_localecodesets.get(domain))
File "C:\Users\user\Miniconda3\lib\gettext.py", line 510, in translation
mofiles = find(domain, localedir, languages, all=True)
File "C:\Users\user\Miniconda3\lib\gettext.py", line 482, in find
for nelang in _expand_lang(lang):
File "C:\Users\user\Miniconda3\lib\gettext.py", line 206, in _expand_lang
loc = locale.normalize(loc)
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)
Additional comments
As you can see, the python interpreter will import the locale.py you are formatting, not the locale from the standard library (in gettext.py) (can be easily confirmed by adding a function called normalize and making it log a critical message.)
Running yapf locale.py from the command line will not produce errors.
The text was updated successfully, but these errors were encountered:
This is due to the fact that the locale.py file you have created is shadowing the native locale module in Python.
This will affect a number of the tools (such as pylint, etc), where they are run with the current workspace as the current working directory. Considering how python works, it will use the locale.py file in the current working directory when importing the locale module.
Try running yapf as a module and you'll get the same error: python -m yapf locale.py.
Solution - Please rename your file from locale.py to something else.
It's true that running python -m yapf locale.py will give the same error. I was running python -m yapf ./subfolder/subsubfolder/locale.py without errors.
lockbot
locked as resolved and limited conversation to collaborators
Jul 11, 2018
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Issue is similar to #706
Environment data
Actual behavior
Format module failed when file name is
locale.py
.Expected behavior
The file will be formatted, no errors in output.
Steps to reproduce:
locale.py
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
)Additional comments
locale.py
you are formatting, not thelocale
from the standard library (ingettext.py
) (can be easily confirmed by adding a function callednormalize
and making it log a critical message.)yapf locale.py
from the command line will not produce errors.The text was updated successfully, but these errors were encountered: