Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/semanal_classprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
TYPE_PROMOTIONS_PYTHON3 = TYPE_PROMOTIONS.copy() # type: Final
TYPE_PROMOTIONS_PYTHON3.update({
'builtins.bytearray': 'bytes',
'builtins.memoryview': 'bytes',
})

# Hard coded type promotions for Python 2.
Expand All @@ -41,6 +42,7 @@
TYPE_PROMOTIONS_PYTHON2.update({
'builtins.str': 'unicode',
'builtins.bytearray': 'str',
'builtins.memoryview': 'str',
})


Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-type-promotion.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def f(x: bytes) -> None: pass
f(bytearray(b''))
[builtins fixtures/primitives.pyi]

[case testPromoteMemoryviewToBytes]
def f(x: bytes) -> None: pass
f(memoryview(b''))
[builtins fixtures/primitives.pyi]

[case testNarrowingDownFromPromoteTargetType]
y = 0.0
y = 1
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/fixtures/primitives.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class bytearray(Sequence[int]):
def __iter__(self) -> Iterator[int]: pass
def __contains__(self, other: object) -> bool: pass
def __getitem__(self, item: int) -> int: pass
class memoryview(Sequence[int]):
def __init__(self, x: bytes) -> None: pass
def __iter__(self) -> Iterator[int]: pass
def __contains__(self, other: object) -> bool: pass
def __getitem__(self, item: int) -> int: pass
class tuple(Generic[T]): pass
class list(Sequence[T]):
def __iter__(self) -> Iterator[T]: pass
Expand Down