Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 pickle: Expected type 'SupportsWrite[bytes]', got 'BinaryIO' instead

A simple program in PyCharm 2024.2.3.(Community Edition)

import pickle

fruits = ['apples', 'oranges', 'banana']

with open('myData.pkl', 'wb') as f:
    pickle.dump(fruits, f)

PyCharm gives me a warning:

Expected type 'SupportsWrite[bytes]', got 'BinaryIO' instead

The program runs correctly, but how do I get rid of this warning?

Python tutorials say that this simple usage of pickle should work.

like image 201
RonLat Avatar asked Jan 16 '26 21:01

RonLat


1 Answers

The warning is erroneous. You can suppress it as follows:

import pickle

fruits = ['apples', 'oranges', 'banana']

with open('myData.pkl', 'wb') as f:
    # noinspection PyTypeChecker
    pickle.dump(fruits, f)

Note:

This is specific to PyCharm

like image 150
Ramrab Avatar answered Jan 19 '26 14:01

Ramrab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!