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

mypy raises error on writing msgpack to binary file #63

Closed
al-zatv opened this issue Dec 26, 2021 · 2 comments
Closed

mypy raises error on writing msgpack to binary file #63

al-zatv opened this issue Dec 26, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@al-zatv
Copy link

al-zatv commented Dec 26, 2021

Line of code which save msgpack to binary file, cause mypy to raise typing error. How can I fix typing here? Save/load works fine, by the way.

@attr.s(auto_attribs=True)
class Phrase(DataClassMessagePackMixin):
    some_data: str
....

with open(base_data_path / "my_data", "wb") as f:
        f.write(phrase.to_msgpack())

Here, mypy raises typing error:
error: Argument 1 to "write" of "IO" has incompatible type "Union[str, bytes, bytearray]"; expected "bytes"

mypy --version

mypy 0.930

@Fatal1ty
Copy link
Owner

Hello @al-zatv

At first glance it seems like to_msgpack method in DataClassMessagePackMixin should return bytes. I will see if we can change it from Union[str, bytes, bytearray] without problems. As a workaround you can use cast:

f.write(cast(bytes, phrase.to_msgpack()))

@Fatal1ty Fatal1ty added the bug Something isn't working label Dec 27, 2021
@Fatal1ty
Copy link
Owner

Fixed in 2.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants