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

typing-extensions 4.6.0 break literal arguments #106

Closed
grochmal opened this issue May 24, 2023 · 1 comment
Closed

typing-extensions 4.6.0 break literal arguments #106

grochmal opened this issue May 24, 2023 · 1 comment

Comments

@grochmal
Copy link

grochmal commented May 24, 2023

With the release of typing-extensions==4.6.0 the Literal type behaves in a weird way, i.e. it does not work at all on python 3.8.x and python3.9.x . Minimal example, let's call it mytap.py

from tap import Tap
from typing import Literal

class Parse(Tap):
    pet: Literal["cat", "dog", "chinchilla"]

args = Parse().parse_args()

Then we go

$ pip install typed-argument-parser typing-extensions==4.5.0
...
$ python mytap.py --pet cat  # nothing happens, as expected
$ python mytap.py --pet horse
usage: mytap.py --pet {cat,dog,chinchilla} [-h]
mytap.py: error: argument --pet: invalid choice: 'horse' (choose from 'cat', 'dog', 'chinchilla')  # correct error message

But with typing extensions 4.6.0

$ pip install typing-extensions==4.6.0
...
$ python mytap.py --pet cat
usage: mytap.py --pet PET [-h]
mytap.py: error: argument --pet: invalid typing.Literal['cat', 'dog', 'chinchilla'] value: 'cat'

The issue popped out on pydantic yesterday. The issue happens because typing extensions changed:

# 3.8+:
if hasattr(typing, 'Literal'):
    Literal = typing.Literal

to

if sys.version_info >= (3, 10, 1):
    Literal = typing.Literal

Now python 3.8.x and python 3.9.x get broken Literal types.

My hopes are that this will get fixed within typing-extensions soon. But in the meantime, could we fix typing-extensions in typing-argument-parser to typing-extensions>=3.7.4,<4.6.0 ?

@swansonk14
Copy link
Owner

Hi @grochmal,

Thank you for raising this issue! We previously required the typing_extensions package to have support for the Literal type in Python version 3.7. However, as of yesterday (6/27/23), Python 3.7 is no longer supported. Therefore, we have removed the dependency on typing_extensions in this commit: c48ef74. This fix will be included in the next release.

Best,
Kyle and Jesse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants