-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Will recursive or mutually recursive bounds on TypeVar be supported? #1561
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
Comments
Reading through python/typing#59 again, it seems like the recursive reference is the same thing as F-bounded polymorphism, which you want to hold off on. Just curious, is that due to the difficulty in implementing the checker properly, or in using bounded quantification correctly? |
Honestly my head explodes each time I try to understand this idea. So maybe
it's also hard to implement? OTOH if you can come up with a patch I'm not
opposed.
…--Guido (mobile)
|
This paper suggests a straightforward implementation, but it'll take awhile for me to wrap my ahead around mypy's codebase. Would it make it into the PEP if mypy supported it? Note that realistic f-bounded polymorphism implementations would have restrictions on what can be written, because the completely general case (with variance) is undecidable. The paper above makes type checking tractable by splitting types in 'shapes' and 'materials'. |
Probably. On Mon, May 30, 2016 at 10:52 AM, smallnamespace notifications@github.com
--Guido van Rossum (python.org/~guido) |
When I looked into this it seemed like this wouldn't quite work for perhaps the most common potential use ( |
I think mypy is doing the right thing here. The above code sample clearly exhibits a type violation, for a couple of reasons:
I recommend closing this issue. |
Reading through the discussion at python/typing#59, there was an example that had
TypeVar
bound that referenced itself. Is this intended to be eventually implemented? The actual PEP just has a bareComparable
.A motivating example (from the Java world) is discussed here, in the context of their
Enum
. An example in Python:If I try to write the recursive bound, I get:
example.py:3: error: Invalid type "example.T"
A similar example where this is needed is at https://github.com/smallnamespace/pymcts/blob/b5e1375e67983ef7b5baa2511c680074fd31b00c/pymcts/tree.py#L78 -- here we need to use the fact that
N
andNode
are identical.The text was updated successfully, but these errors were encountered: