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
I just tried and groupby([1, 2, 3, 3, 3], None) indeed doesn't crash, but according to typeshed this call is illegal. You can open an issue there, if you are sure this is actually intended/documented behavior, or you can also try something like this:
Thanks will do. Wasn't sure if this was a mypy issue or a typeshed issue.
With the @overloads for itertools.groupby(), should Optional[Callable[[T], S]] match?
While you can do if key is not None: the problem with that is you can't effectively describe the type of iterator, e.g.:
iterator: Iterator[Tuple[S, Iterator[T]]]
if key is not None:
iterator = itertools.groupby(iterable, key)
else:
iterator = itertools.groupby(iterable) # Fail
You get the error:
error: Incompatible types in assignment (expression has type "Iterator[Tuple[T, Iterator[T]]]", variable has type "Iterator[Tuple[S, Iterator[T]]]")
And you can't declare the types in each branch because you will get a redeclaration error Name 'iterator' already defined on line ...
With the @overloads for itertools.groupby(), should Optional[Callable[[T], S]] match?
No, with current definition in typeshed it is illegal, Optional means it can be None (not that it is an optional argument), while with current definition neither of two overloads accepts None.
Activity
ilevkivskyi commentedon Feb 11, 2019
I just tried and
groupby([1, 2, 3, 3, 3], None)indeed doesn't crash, but according to typeshed this call is illegal. You can open an issue there, if you are sure this is actually intended/documented behavior, or you can also try something like this:achampion commentedon Feb 11, 2019
Thanks will do. Wasn't sure if this was a
mypyissue or atypeshedissue.With the
@overloadsforitertools.groupby(), shouldOptional[Callable[[T], S]]match?While you can do
if key is not None:the problem with that is you can't effectively describe the type ofiterator, e.g.:You get the error:
And you can't declare the types in each branch because you will get a redeclaration error
Name 'iterator' already defined on line ...ilevkivskyi commentedon Feb 11, 2019
No, with current definition in typeshed it is illegal,
Optionalmeans it can beNone(not that it is an optional argument), while with current definition neither of two overloads acceptsNone.