“Protocols cannot be used with isinstance()” - why not?

前端 未结 2 1164
一整个雨季
一整个雨季 2021-02-05 13:02

The new typing module contains several objects with names like \"SupportsInt\" (-Float, -Bytes, etc.). The name, and the descriptions on the documentation page for

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 13:53

    As the documentation says: At runtime, isinstance(x, T) will raise TypeError. In general, isinstance() and issubclass() should not be used with types. ( https://docs.python.org/3/library/typing.html?highlight=typing#typing.TypeVar )

提交回复
热议问题