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

SyntaxWarning problems are hidden after byte-code compilation #130378

Open
andersk opened this issue Feb 20, 2025 · 0 comments
Open

SyntaxWarning problems are hidden after byte-code compilation #130378

andersk opened this issue Feb 20, 2025 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@andersk
Copy link
Contributor

andersk commented Feb 20, 2025

Bug report

Bug description:

$ echo '"\s"' > test.py
$ python --version
Python 3.13.1
$ python -m test
/tmp/test.py:1: SyntaxWarning: invalid escape sequence '\s'
  "\s"
$ python -m test
$ python -m test
$ rm -r __pycache__
$ python -m test
/tmp/test.py:1: SyntaxWarning: invalid escape sequence '\s'
  "\s"
$ python -m test

I know that’s because byte-code compilation bypasses the parser. However, the resulting behavior makes it difficult to discover SyntaxWarning problems within modules, especially ones in third-party modules for which pip hides the compilation output.

$ pip install glom==22.1.0
Collecting glom==22.1.0
  Using cached glom-22.1.0-py2.py3-none-any.whl.metadata (4.9 kB)
Collecting boltons>=19.3.0 (from glom==22.1.0)
  Using cached boltons-25.0.0-py3-none-any.whl.metadata (6.5 kB)
Collecting attrs (from glom==22.1.0)
  Using cached attrs-25.1.0-py3-none-any.whl.metadata (10 kB)
Collecting face>=20.1.0 (from glom==22.1.0)
  Using cached face-24.0.0-py3-none-any.whl.metadata (1.1 kB)
Using cached glom-22.1.0-py2.py3-none-any.whl (100 kB)
Using cached boltons-25.0.0-py3-none-any.whl (194 kB)
Using cached face-24.0.0-py3-none-any.whl (54 kB)
Using cached attrs-25.1.0-py3-none-any.whl (63 kB)
Installing collected packages: boltons, attrs, face, glom
Successfully installed attrs-25.1.0 boltons-25.0.0 face-24.0.0 glom-22.1.0
$ python -m glom
{}
$ rm -r /tmp/v/lib/python3.13/site-packages/glom/__pycache__
$ python -m glom
/tmp/v/lib/python3.13/site-packages/glom/matching.py:764: SyntaxWarning: invalid escape sequence '\ '
  """The :class:`Switch` specifier type routes data processing based on
{}
$ python -m glom
{}

It would be better if compilation could record the warning in the .pyc file such that it gets re-emitted on every load, even though the parser was bypassed.

(This was mentioned in #77093 (comment), but it seems nobody took up the suggestion to file this as a separate issue.)

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@andersk andersk added the type-bug An unexpected behavior, bug, or error label Feb 20, 2025
@tomasr8 tomasr8 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants