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
MappedAsDataclass Optional generates non-Optional typing annotations #9855
Comments
Hi, That's expected. If you try to run the above code it errors with:
Follow what the error suggests and it should work |
This is a bug of MyPy. pyright or pylance type check the code correctly. cc @zzzeek from typing import Any, Generic, TypeVar, dataclass_transform, reveal_type
T = TypeVar("T")
class Desc(Generic[T]):
def __set__(self, instance: Any, value: "Desc[T]| T") -> None:
...
@dataclass_transform(field_specifiers=(Desc,))
class DescMeta(type):
pass
class DescBase(metaclass=DescMeta):
pass
class Foo(DescBase):
bar: Desc[int | None]
reveal_type(Foo.__init__)
Foo(bar=None) This prints in mypy
while pyright correctly says
|
@zzzeek I don't remember if you already reported this one to mypy |
yes it's python/mypy#15020 |
so if that's the issue, then dupe of #9617 |
Ensure stubs packages are not installed
sqlalchemy-stubs
andsqlalchemy2-stubs
are not compatible with v2)Verify if the api is typed
Describe the typing issue
When having
MappedAsDataclass
in the class hierarchy, Mypy reportsOptional
attributes as notOptional
.The generated DDL is correct, without the
NOT NULL
partTo Reproduce
Error
Versions
Additional context
This seems oddly similar to #9567, but the referenced mypy issue, python/mypy#13856, is marked as resolved in 1.2 (also in docs)
Thank you
The text was updated successfully, but these errors were encountered: