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. |
Beta Was this translation helpful? Give feedback.
-
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
Repository
cannot be made generic overP
(Repository[**P, T]
) sinceUserDatabase
cannot specifyP
directly (User
only accepts keyword arguments), are there any alternatives?Beta Was this translation helpful? Give feedback.
All reactions