madzak / python-json-logger

Json Formatter for the standard python logger
BSD 2-Clause "Simplified" License
1.74k stars 231 forks source link

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

Closed horaceleung closed 1 year ago

horaceleung commented 2 years ago

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

madzak commented 2 years ago

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

horaceleung commented 2 years ago

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

q0w commented 2 years ago

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

madzak commented 1 year ago

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