Skip to content

Incompatible types in assignment (expression has type "BinaryIO", variable has type "TextIO") #10982

Closed
@jdhao

Description

@jdhao

Bug Report

mypy reports correct reading of pickle files as error.

To Reproduce

Use the following code:

import json
import pickle

with open('test_ids.json') as f:
    my_ids = json.load(f)

for _id in my_ids:
    id_path = f'{_id}.pkl'

    with open(id_path, 'rb') as f:
        v2_feat = pickle.load(f)

Then use mypy to check the code: mypy test.py

Expected Behavior

No error occurs.

Actual Behavior

I see the following errors:

test.py:10: error: Incompatible types in assignment (expression has type "BinaryIO", variable has type "TextIO")
test.py:11: error: Argument 1 to "load" has incompatible type "TextIO"; expected "IO[bytes]"

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.7.6
  • Operating system and version: CentOS 7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions