Open barraponto opened 1 year ago
So, can you narrow the generic TypeVar
to a subclass of two classes, as to ensure it has every property in both classes? No. Well, not in Python, at least for now. There's a Stackoverflow Q&A that correctly points the issue to the lack of Type Intersections in Python. There's a mile-long issue about it in the python/typing repo, but TLDR we're going to wait a while for support to land.
As a pragmatic solution to this issue, can we make BeanieBaseUserDocument
importable from fastapi_users.db
? Would subclassing it have any nefarious side effect?
Describe the bug
Pyright complains when
BeanieUserDatabase
gets a subclass of bothBeanieBaseUser
andbeanie.Document
.To Reproduce
Expected behavior
No type errors.
Configuration
Additional context
Particularly, I see
BeanieBaseUserDocument
defined as literally a subclass of bothBeanieBaseUser
andbeanie.Document
. But defining aTypeVar
bond toBeanieBaseUserDocument
does not accept another subclass of the same classes :/