You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Assignment to next in class body of Iterator elicits error (in PY2 mode) #2503
__tmp__.py: note: In class "X":
__tmp__.py:7: error: Incompatible types in assignment (expression has type Callable[[X], A], variable has type Callable[[Iterator[A]], A])
This is a general problem (not just for next). It prevents us from using
mypy with this PR for our own "C" repo (for totally valid code). Should we
roll back the PR or ask its author to come up with a fix? I'm not sure how
involved the fix would be.
Just to check if I understand the problem correctly, the following should also pass mypy not? (but it doesn't before the revert; same error as above)
T = TypeVar("T")
class B(Generic[T]):
v = None # type: T
def n(self):
# type: () -> T
return self.v
class C(B[int]):
def m(self):
# type: () -> int
return 1
n = m
Activity
JukkaL commentedon Nov 28, 2016
The type of
nextin the class body should likely be inferred asCallable[[X], A](i.e., the type ofselfshould be derived from the enclosing class).gvanrossum commentedon Nov 28, 2016
Revert "For class variables, lookup type in base classes (#1338, #2022,
TrueBrain commentedon Nov 29, 2016
Just to check if I understand the problem correctly, the following should also pass mypy not? (but it doesn't before the revert; same error as above)
gvanrossum commentedon Nov 29, 2016
TrueBrain commentedon Nov 29, 2016
Found an even more elegant example:
Pushed a fix, but I would love some feedback if this is an okay way to go.
Additionally, would you be able to check if with this version your repo does validate successfully?
gvanrossum commentedon Nov 30, 2016
Yes, that example is better because it shows the problem is not due to generics.
Where's your fix? You're going to have to create a new PR.
JukkaL commentedon Nov 30, 2016
Both examples look good.
gvanrossum commentedon Dec 5, 2016
However here's a more complex example:
JukkaL commentedon Jan 16, 2017
Note that this becomes relevant after #2510 is merged.