-
Notifications
You must be signed in to change notification settings - Fork 246
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
What does it mean to inherit from a generic type without specifying type parameters? #85
Comments
Good catch. I only implemented this behavior (in GenericMeta IIRC) because I wasn't sure and I think Jukka wasn't around to respond in real time. I think Jukka's interpretation is fine. Can you start adding explicit type variables to all those cases and perhaps also think about how to implement Jukka's behavior? (And I guess the PEP needs to mention this, unless it's already there.) |
@JukkaL - I'm not sure what to do here. Is the PEP text up to date? Then it would just be a bug in my typing.py. Or does the PEP need to be updated? Or do we still need to decide what to do? |
I just chatted with @JukkaL. The intention is clear. The PEP text could be clearer. The implementation in typing.py should be changed; at the very least the generic classes should all use explicitly type variables. |
…able[Any]. This addresses, but does not fix, issue #85.
Updated the PEP. Still need to fix this in typing.py. |
Currently class ItemsView(MappingView, Generic[KT, VT_co],
extra=collections_abc.ItemsView):
pass But in the context of this issue should |
I think a type checker should infer that if d is a Dict[str, int] then
Or alternatively we could use a type variable that is bound to Tuple? I'm |
I think ideally it would be: class ItemsView(MappingView[Tuple[KT, VT_co]],
extra=collections_abc.ItemsView):
pass however, this is currently impossible. There is a TODO in |
I've got a feeling there's still an issue here (separate from #115). Several examples in the PEP create generic classes by simply subclassing an existing generic class and providing new type variables; e.g. class LinkedList(Iterable[T], Container[T]):
... However mypy reject this -- you have to add Generic[T] into the mix. I'm not sure whether to claim that mypy is wrong here or whether to change this in the PEP. For simple cases it seems that the need to add Generic[T] is just redundant -- but there are also complex cases that typing.py currently doesn't allow at all but that would be disambiguated by this rule, e.g. class B(Generic[X, Y]): ...
class C(B[Tuple[Y, X], Z]): ... What should the parameters of C be in this case, and in what order? If we require class C(B[Tuple[Y, X], Z], Generic[X, Y, Z]): ... there would be no ambiguity. |
Argh. This issue is actually about the interpretation of I'm sorry for the mess. There are too many related problems and when I wrote typing.py I wasn't aware of either how mypy behaves or what the corner cases were. In any case we should decide what to do for these problems in the PEP and in typing.py before CPython 3.5.2 goes out, and change mypy (if needed) when we have a decision. |
I think that leaving For example, there rules would cover a lot of interesting cases and they would be unambiguous (though a little ad-hoc):
Alternatively, we could make If there is no
Using |
I agree with @JukkaL , it is more consistent if |
OK, let's go with Jukka's most elaborate plan for the PEP. It's fine
if mypy catches up in two phases: first the simple rules, later the
more advanced version. After all, we can always make mypy accept
something by just adding Generic[...], which is always fine for the
PEP.
Also agreed plain Iterator means Iterator[Any].
|
The PEP already includes the correct language about Iterator meaning Iterator[Any]; it's just typing.py that doesn't implement this. I've just added some words (examples, really) to the PEP that imply Jukka's simpler set of rules in rev eeb7393. Please review. |
I'm closing this issue, because (a) the original question has been answered (it means X[Any]) and (b) I've updated the PEP with text that follows Jukka's proposal. I'm keeping #115 open to track the necessary changes to typing.py for both issues. |
In the current implementation of typing.py the
Iterator
type is defined as follows:From the implementation point of view this means that
Iterator
is a generic type withT_co
as its type parameter. @JukkaL argues that it should mean thatIterator
is actually the concrete typeIterator[Any]
.The text was updated successfully, but these errors were encountered: