-
-
Notifications
You must be signed in to change notification settings - Fork 386
converter expected to return a Tuple where perhaps an Iterable should do #474
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
Hrm. I'm realizing that there's no way that |
I suppose the answer is to play with mypy's |
I'm not having any luck… Here's a simpler example: from typing import Iterable, Sequence, Tuple
from attr import attrib, attrs
RawHeader = Tuple[bytes, bytes]
RawHeaders = Sequence[RawHeader]
def normalizeRawHeadersFrozen(headerPairs):
# type: (Iterable[Iterable[bytes]]) -> RawHeaders
return tuple()
@attrs(frozen=True)
class Test(object):
rawHeaders = attrib(
converter=normalizeRawHeadersFrozen,
default=(),
) # type: RawHeaders
reveal_type(RawHeaders)
reveal_type(normalizeRawHeadersFrozen)
reveal_type(Test.rawHeaders) And test.py:13: error: Argument "converter" to "attrib" has incompatible type "Callable[[Iterable[Iterable[bytes]]], Sequence[Tuple[bytes, bytes]]]"; expected "Optional[Callable[[Any], Tuple[]]]"
test.py:18: error: Revealed type is 'def () -> typing.Sequence[Tuple[builtins.bytes, builtins.bytes]]'
test.py:19: error: Revealed type is 'def (headerPairs: typing.Iterable[typing.Iterable[builtins.bytes]]) -> typing.Sequence[Tuple[builtins.bytes, builtins.bytes]]'
test.py:20: error: Revealed type is 'typing.Sequence[Tuple[builtins.bytes, builtins.bytes]]' What I don't get is why it thinks that |
Sounds like a case for the typing crew. :) |
What version of mypy are you running? I'm not seeing that error in the latest Aha. Doing a |
Oh, great! Thanks for finding that @euresti. |
Closing here. |
Yay SEPs. ;) |
After updating
mypy
from0.630
to0.650
for Klein, I get this error:src/klein/_headers.py:172:18: error: Argument "converter" to "attrib" has incompatible type "Callable[[Iterable[Iterable[bytes]]], Sequence[Tuple[bytes, bytes]]]"; expected "Optional[Callable[[Any], Tuple[]]]"
If I'm reading this correctly, the provided converter is a
Callable
(OK) and takes one argument (OK) and returns aSequence
(not OK:Tuple
expected).The converter specified in src/klein/_headers.py:172 is
normalizeRawHeadersFrozen
:This implementation does return a
tuple
, but I wanted to limit my commitment to aSequence
. I think thatconverter
should be happy with aSequence
in practice, so I'd like to lobby for a looser requirement here.The text was updated successfully, but these errors were encountered: