-
Notifications
You must be signed in to change notification settings - Fork 217
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
[BUG] Link
type annotations don't play well with static type checkers (pylance, mypy)
#820
Comments
Hi @ldorigo , Thank you for the catch! |
Is there any way or workaround to currently type it properly? I'm having to add #type: ignore all over our codebase 😞 |
Yeah in general I would like the typing system to look at a |
Just to mention that I've run into this issue as well, so I think the only workaround for now is to ignore the type check on these links or to do casting? That is, either MyDocument.linked_type # type: ignore[attr-defined] or from typing import cast
cast(MyDocument.linked_type, UnderlyingType) |
I'd rather have a more robust solution that was built in with Beanie. But I've had success doing the following as a temporary measure. from typing import TypeAlias
from beanie import Link as BeanieLink
if TYPE_CHECKING:
_T = TypeVar("_T", bound=Document)
Link: TypeAlias = _T
else:
Link = BeanieLink What it does is when type checking it aliases Link to be the Document class it's wrapping. |
Describe the bug
Links to related documents annotated as
Link[xx]
get the typeLink[xx]
, which gives type errors when trying to access e.g.obj.linkedobj
.To Reproduce
The text was updated successfully, but these errors were encountered: