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

create_model_from_typeddict reports a type error when given the correct input type #3008

Closed
lewiswolf opened this issue Jul 22, 2021 · 0 comments · Fixed by #3047
Closed
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@lewiswolf
Copy link

Checks

  • [x ] I added a descriptive title to this issue
  • [x ] I have searched (google, github) for similar issues and couldn't find anything
  • [x ] I have read and followed the docs and still think this is a bug

Bug

When running mypy using create_model_from_typeddict() I get a type error for the input - the code however works as expected. When I run the code below, using mypy myscript.py, I get the following error.

error: Argument 1 to "create_model_from_typeddict" has incompatible type "Type[SomeDict]"; expected "Type[TypedDict]"

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

pydantic version: 1.8.2
pydantic compiled: True
install path: /Users/lewiswolstanholme/.local/share/virtualenvs/drum-shape- 
predictor-YZkKhtr_/lib/python3.9/site-packages/pydantic
python version: 3.9.6 (default, Jun 29 2021, 06:20:32)  [Clang 12.0.0 (clang-1200.0.32.29)]
platform: macOS-10.15.7-x86_64-i386-64bit
optional deps. installed: ['typing-extensions']
from typing import TypedDict 
import pydantic


class SomeDict(TypedDict):
    val: int
    name: str

# this could be a valid/invalid declaration
obj: SomeDict = {
    'val': 12,
    'name': 'John',
}

# validate with pydantic
try:
    pydantic.create_model_from_typeddict(SomeDict)(**obj)

except pydantic.ValidationError as exc: 
    print(f"ERROR: Invalid schema: {exc}")
@lewiswolf lewiswolf added the bug V1 Bug related to Pydantic V1.X label Jul 22, 2021
PrettyWood added a commit to PrettyWood/pydantic that referenced this issue Jul 30, 2021
PrettyWood added a commit to PrettyWood/pydantic that referenced this issue Jul 30, 2021
PrettyWood added a commit to PrettyWood/pydantic that referenced this issue Jul 30, 2021
PrettyWood added a commit that referenced this issue Sep 4, 2021
* fix: make `create_model_from_typeddict` mypy compliant

closes #3008

* add comment
jpribyl pushed a commit to liquet-ai/pydantic that referenced this issue Oct 7, 2021
* fix: make `create_model_from_typeddict` mypy compliant

closes pydantic#3008

* add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant