FelixTheC / strongtyping

Decorator which checks whether the function is called with the correct type of parameters.
https://pypi.org/project/strongtyping/
108 stars 3 forks source link

Cannot import match_typing on Python 3.10.4 with strongtyping 3.11.1 #117

Closed AndreRicardo-Zoetis closed 1 year ago

AndreRicardo-Zoetis commented 1 year ago

Describe the bug

I'm aware of issue https://github.com/FelixTheC/strongtyping/issues/108 but cannot see how is fixed in 3.11.1.

The setup.py only states python_requires=">=3.7", so I'm not sure what I'm doing wrong?

Python Version used Python 3.10.4

Package Version used strongtyping 3.11.1

Addon in use strongtyping_modules [no]

To Reproduce Steps to reproduce the behavior:

docker run -it --rm python:3.10.4-slim-bullseye bash

pip install strongtyping==3.11.1

python3 -c 'from strongtyping.strong_typing import match_typing'

Results in import error

root@d1c3b68452de:/# python3 -c 'from strongtyping.strong_typing import match_typing'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/strongtyping/strong_typing.py", line 6, in <module>
    from typing import NotRequired, Required, Type, get_args, get_origin
ImportError: cannot import name 'NotRequired' from 'typing' (/usr/local/lib/python3.10/typing.py)

Expected behavior

Did not expect an import Error.

Screenshots

root@d1c3b68452de:/# python3 --version
Python 3.10.4
root@d1c3b68452de:/# pip install strongtyping==3.11.1
Collecting strongtyping==3.11.1
  Downloading strongtyping-3.11.1-py3-none-any.whl (22 kB)
Installing collected packages: strongtyping
Successfully installed strongtyping-3.11.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 22.0.4; however, version 23.1.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@d1c3b68452de:/# python3 -c 'from strongtyping.strong_typing import match_typing'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/strongtyping/strong_typing.py", line 6, in <module>
    from typing import NotRequired, Required, Type, get_args, get_origin
ImportError: cannot import name 'NotRequired' from 'typing' (/usr/local/lib/python3.10/typing.py)

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

FelixTheC commented 1 year ago

please use a version with 3.10.x I set the version of my package to the matched Python version. For your case please use 3.10.7

pip install strongtyping==3.10.7
AndreRicardo-Zoetis commented 1 year ago

Thank you for your reply @FelixTheC.

Out of curiosity, if that is the case why isn't the python_requires also pinned to the python version?

https://github.com/FelixTheC/strongtyping/blob/20ebb17cdf55ec8b00066c67ae87a929134a92f5/setup.py#L34

FelixTheC commented 1 year ago

good point :D I should really adjust it in the near future.

AndreRicardo-Zoetis commented 1 year ago

Thanks!

For my benefit, could you also help me understand why isn't strongtyping importing as

from __future__ import annotations  # for Python 3.7-3.9

from typing_extensions import NotRequired, TypedDict  # for Python <3.11 with (Not)Required

As documented in PEP 655 usage?

FelixTheC commented 1 year ago

I only use from future imports for developing only. I think a library which is not marked as Beta or similar shouldn't do this. There is a official extension for NotRequired which is supported in the 3.10.7 version.