Skip to content
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

unpacking bytes #5547

Closed
dfroger opened this issue Aug 31, 2018 · 2 comments
Closed

unpacking bytes #5547

dfroger opened this issue Aug 31, 2018 · 2 comments

Comments

@dfroger
Copy link
Contributor

dfroger commented Aug 31, 2018

This behaviour is strange (mypy 0.620):

async def get_foo() -> bytes:
    return b'foo'

async def bar() -> bytes:
    foo = await get_foo()
    reveal_type(foo)  # builtins.bytes*

    x, y = foo
    reveal_type(x)  # builtins.int*
    reveal_type(y)  # builtins.int*

    z, _ = foo
    reveal_type(x)  # builtins.int*
    reveal_type(_)  # Any

    return foo

@gvanrossum
Copy link
Member

What exactly is strange to you? To me all that looks as expected -- what did you expect to be different?

Assuming you're talking about the typing of _, this has nothing to do with bytes or async. It is due to the special-casing of _ as a throw-away variable.

The int type for bytes items is also correct. And mypy doesn't catch the length mismatch between b'foo' and the unpacking into two variables since the length of a sequence is not part of its type.

@dfroger
Copy link
Contributor Author

dfroger commented Aug 31, 2018

@gvanrossum thanks for your helpfull answer, seems that I forgot that x, y = b'xy' is correct and give two integers... Everything is actually clear and work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants