-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
'"ClassName" expects no type arguments, but 1 given' while inheriting from Iterable #2425
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
It looks like you want T = TypeVar('T')
class IterableWrapper(Iterator[T], Iterable[T], BaseWrapper, Generic[T]):
... Also you shouldn't need Iterable[T] because Iterator already inherits from Iterable. I am presuming your BaseWrapper is not generic. |
Note that |
Righ. Thanks for this explanation. I think I'm going to write a big tutorial on mypy in the coming months. |
Ooops. Forgot to ask: why do I have to inherit from Iterator[T] AND Generic[T]? Iterator[T] is not a generic already ? |
Oh, that's a separate issue. According to PEP 484 you shouldn't need the
Generic[T] unless you have multiple type variables and you want to specify
their order, but mypy currently always requires the Generic[T]. It's issue
#302.
|
I have a class looking like this:
And a function type definition later going:
# type: (...) -> IterableWrapper[tuple[T, T2]]
Mypy complains:
src/ww/wrappers/iterables.py:600: error: "IterableWrapper" expects no type arguments, but 1 given
While:
# type: (...) -> IterableWrapper
and# type: (...) -> Iterable[tuple[T, T2]]
don't get any warning.I was expecting that, inheriting from
Iterable,
I could doIterableWrapper[tuple[T, T2]]
like I would doIterable[tuple[T, T2]]
and benefit from code checking on yielded elements.The text was updated successfully, but these errors were encountered: