EDIT: It was my bad. I should have used issubclass
instead of isinstance
, as suggested in @kevin-mayo 's answer. Then everything works.
I recently stumbled upon a weird behaviour of pycharm's type hinting, which later revealed a trouble with python itself. I have a method which takes a stream, so I set the type as io.BaseIO
. However, when I passed a BytesIO
to it, it gave me a warning. I checked the following:
>>> io.BytesIO.__mro__
(<class '_io.BytesIO'>, <class '_io._BufferedIOBase'>, <class '_io._IOBase'>, <class 'object'>)
>>> isinstance(io.BytesIO, io.IOBase)
False
This contradicts what Python docs say, so I'm really confused.
I'm using Python 3.7.
I realize the duck typing way of doing this, but keep in mind that I'm not making a strict type check, but a convenient type hint.