-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Mypy plugin crashes when encountering from_orm
method on user's classes
#5187
Comments
I'm having to just |
Can you share some code showing how you are using it to produce this error? |
I don't get this error running mypy over the code in the snippet you've shared; however, I looked into it a bit and I see where it needs handling, and I think I it should be straightforward to fix if you can give me some code that shows how to reproduce the issue. |
Oh also — could you share what version of mypy you are using? (You can find this by running |
$ mypy --version
mypy 1.1.1 (compiled: yes) It errors out on provided code: import abc
from collections.abc import Iterable
from typing import Generic, TypeVar
_TModel = TypeVar("_TModel")
_TType = TypeVar("_TType")
class OrmMixin(Generic[_TModel, _TType]):
@classmethod
@abc.abstractmethod
def from_orm(cls, model: _TModel) -> _TType:
raise NotImplementedError
@classmethod
def from_orm_optional(cls, model: _TModel | None) -> _TType | None:
if model is None:
return None
return cls.from_orm(model)
@classmethod
def from_orm_list(cls, models: Iterable[_TModel]) -> list[_TType]:
return [cls.from_orm(model) for model in models] Mypy config: [tool.mypy]
python_version = "3.11"
plugins = [
"pydantic.mypy",
]
check_untyped_defs = true
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_any_generics = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
warn_unreachable = true
strict_optional = true
strict_equality = true |
# pyproject.toml
dependencies = [
"mypy>=1.1.1",
"pydantic>=1.10.6",
] $ pip freeze
mypy==1.1.1
mypy-extensions==1.0.0
pydantic==1.10.6
typing_extensions==4.5.0 |
see #5192 |
Same behavior with 1.0.1 |
@ThirVondukr thank you for your help/patience. This turned out to have an easy fix so I was able to get it in. That said, I think some of the other issues listed in #5192 will be more involved to resolve, so I don't want to promise as quick of a turn-around on those. |
Don't stress it, thanks for your help 😃 |
Initial Checks
Description
I have a
OrmMixin
(provided in example code) to help with mappingsqlalchemy
models intostrawberry-graphql
models.Mypy plugin seems to have problems with
from_orm
method and works fine if it's renamed, for example intofrom_orm_
.Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: