Inferring parameter types and return type of a type[T]
#9330
Replies: 1 comment
|
It took me a while to convince myself that this should work, but I agree it should. It's a clever pattern — one that pushes the boundaries of the type system and veers into territory that is not well defined currently in the typing spec. The reason it's not currently working in is because of the way that pyright determines protocol compatibility when callable attributes are present in the protocol. A callable attribute is generally assumed to be called with a Thinking about this more, I'll note that mypy doesn't handle this pattern either, so if you want it to work with mypy, you'll need to work with the mypy maintainers to get that fixed. |
Uh oh!
There was an error while loading. Please reload this page.
Is the following supposed to work?
(playground)
Expected:
Actual:
This seems to be a rare pattern, so I don't actually expect it to be supported. Given that
Repositorycannot be made generic overP(Repository[**P, T]) sinceUserDatabasecannot specifyPdirectly (Useronly accepts keyword arguments), are there any alternatives?All reactions