-
-
Notifications
You must be signed in to change notification settings - Fork 2k
_operator._compare_digest is incorrectly typed #15617
Copy link
Copy link
Open
Description
When working on #15611, I realized that the internal _compare_digest function, which accepted two strings or anything that implements the buffer protocol (so-called 'bytes-like objects'), was annotated to only take two AnyStrs, the upper bound of which is str and bytes (though type checkers understand that bytearray is accepted also). Therefore, the following snippet, which prints True at runtime without fault, will fail type checking:
import _operator
class test:
def __buffer__(self, flags, /): return memoryview(b'')
def __release_buffer__(self, buffer, /): buffer.release()
print(_operator._compare_digest(test(), test()))The argument annotation should be changed. Another TypeVar, constrained to str and collections.abc.Buffer, is likely needed.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels