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

Cannot use Literal from standard library in 3.8 #1026

layday opened this issue Nov 24, 2019 · 1 comment · Fixed by #1027

Cannot use Literal from standard library in 3.8 #1026

layday opened this issue Nov 24, 2019 · 1 comment · Fixed by #1027
bug help wanted


Copy link

@layday layday commented Nov 24, 2019


  • OS: macOS
  • Python version import sys; print(sys.version): 3.8.0
  • Pydantic version import pydantic; print(pydantic.VERSION): 1.1.1

Annotating models with the built-in literal in Python 3.8 in the absence of typing_extensions does not work because is_literal_type only checks if Literal is available from typing_extensions. Please see the snippet below.

$ cat
from typing import Literal
from pydantic import BaseModel

class Foo(BaseModel):
    bar: Literal['']

$ python3
Traceback (most recent call last):
  File "", line 5, in <module>
    class Foo(BaseModel):
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/", line 192, in __new__
    fields[ann_name] = ModelField.infer(
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/", line 260, in infer
    return cls(
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/", line 237, in __init__
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/", line 307, in prepare
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/", line 359, in _type_analysis
    if issubclass(origin, Tuple):  # type: ignore
  File "/nix/store/mnl1njrv6g2jcs69kq0cy19766kcgc5n-python3-3.8.0/lib/python3.8/", line 771, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
$ pip3 install typing_extensions
Collecting typing_extensions
  Using cached
Installing collected packages: typing-extensions
Successfully installed typing-extensions-
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ python3
@layday layday added the bug label Nov 24, 2019
Copy link

@samuelcolvin samuelcolvin commented Nov 24, 2019

Thanks for reporting. PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug help wanted
None yet

Successfully merging a pull request may close this issue.

2 participants