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

sys.stdout.buffer has incorrect type? #2527

Open
vlovich opened this issue Oct 18, 2018 · 1 comment
Open

sys.stdout.buffer has incorrect type? #2527

vlovich opened this issue Oct 18, 2018 · 1 comment
Labels
topic: io I/O related issues

Comments

@vlovich
Copy link

vlovich commented Oct 18, 2018

mypy test.py
test.py:10: error: Argument 1 to "test" has incompatible type "BinaryIO"; expected "BufferedIOBase"

cat test.py

import io
import sys

class C(io.BufferedIOBase):
  pass

def test(c: io.BufferedIOBase):
  assert isinstance(c, io.BufferedIOBase)

test(sys.stdout.buffer)
test(C())

python3 test.py

As we can see the isinstance check passes but mypy asserts

@srittau
Copy link
Collaborator

srittau commented Nov 29, 2018

This is currently hard to fix and depends on typeshed using protocols for file argument types. See python/typing#564 for more information.

@srittau srittau added the topic: io I/O related issues label Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: io I/O related issues
Projects
None yet
Development

No branches or pull requests

2 participants