python-json-logger icon indicating copy to clipboard operation
python-json-logger copied to clipboard

invalid syntax: RESERVED_ATTRS: Tuple[str, ...] = (

Open horaceleung opened this issue 2 years ago • 3 comments

We are deploying code that has a dependency on jsonlogger and it is now throwing the below syntax error. any help would be appreicated. (we are using python 3.5)

plugins_1 | from pythonjsonlogger import jsonlogger plugins_1 | File "/usr/local/lib/python3.5/site-packages/pythonjsonlogger/jsonlogger.py", line 20 plugins_1 | RESERVED_ATTRS: Tuple[str, ...] = ( plugins_1 | ^ plugins_1 | SyntaxError: invalid syntax drsuser_plugins_1 exited with code 1

horaceleung avatar Jul 17 '22 10:07 horaceleung

What Python version are you running this?

Line 20 syntax was updated to support PEP 561 (https://peps.python.org/pep-0561/) which distributes types with the package, specifically here it's the ...: Tuple[str, ...] part, in this PR: https://github.com/madzak/python-json-logger/commit/4c72bedd4afb1e7c3aee05e256d5c741a8db58f7

madzak avatar Jul 17 '22 13:07 madzak

I'm running this on python 3.5 and haven't had this problem before on v2.0.2

The full log below:

plugins_1 | Traceback (most recent call last): plugins_1 | File "/usr/local/bin/py-skygear", line 5, in plugins_1 | from skygear.bin import main plugins_1 | File "/usr/local/lib/python3.5/site-packages/skygear/init.py", line 24, in plugins_1 | from .decorators import ( plugins_1 | File "/usr/local/lib/python3.5/site-packages/skygear/decorators.py", line 17, in plugins_1 | from .registry import get_registry plugins_1 | File "/usr/local/lib/python3.5/site-packages/skygear/registry.py", line 18, in plugins_1 | from .utils.logging import setLoggerTag plugins_1 | File "/usr/local/lib/python3.5/site-packages/skygear/utils/logging.py", line 17, in plugins_1 | from pythonjsonlogger import jsonlogger plugins_1 | File "/usr/local/lib/python3.5/site-packages/pythonjsonlogger/jsonlogger.py", line 20 plugins_1 | RESERVED_ATTRS: Tuple[str, ...] = ( plugins_1 | ^ plugins_1 | SyntaxError: invalid syntax

horaceleung avatar Jul 17 '22 15:07 horaceleung

~~You should add from __future__ import annotations for older python versions~~ nvm: py35 support is dropped: https://github.com/madzak/python-json-logger/blob/705fe99cee679dbb57c3a2028dcdada3b60aaef4/setup.py#L32

q0w avatar Jul 28 '22 05:07 q0w

If you run into this on later versions feel free to re-open.

madzak avatar Feb 15 '23 18:02 madzak