10000 Allow objects matching `SupportsKeysAndGetItem` to be unpacked by bryanforbes · Pull Request #14990 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Allow objects matching SupportsKeysAndGetItem to be unpacked #14990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix some failing tests
  • Loading branch information
bryanforbes committed Apr 4, 2023
commit 0f4354949e7298acc1199d00ce49b406fa3aad99
2 changes: 1 addition & 1 deletion mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def parse_test_case(case: DataDrivenTestCase) -> None:
with open(src_path, encoding="utf8") as f:
files.append((join(base_path, "typing.pyi"), f.read()))
elif item.id == "_typeshed":
# Use an alternative stub file for the typing module.
# Use an alternative stub file for the _typeshed module.
assert item.arg is not None
src_path = join(os.path.dirname(case.file), item.arg)
with open(src_path, encoding="utf8") as f:
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
type_state.add_all_protocol_deps(deps)

for source, targets in sorted(deps.items()):
if source.startswith(("<enum", "<typing", "<mypy")):
if source.startswith(("<enum", "<typing", "<mypy", "<_typeshed.")):
# Remove noise.
continue
line = f"{source} -> {', '.join(sorted(targets))}"
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/fine-grained-dataclass-transform.test
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class A(Dataclass):

[out]
main:7: error: Unexpected keyword argument "x" for "B"
builtins.pyi:12: note: "B" defined here
builtins.pyi:13: note: "B" defined here
main:7: error: Unexpected keyword argument "y" for "B"
builtins.pyi:12: note: "B" defined here
builtins.pyi:13: note: "B" defined here
==

[case frozenInheritanceViaDefault]
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/fixtures/typing-async.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Sequence(Iterable[T_co], Container[T_co]):
def __getitem__(self, n: Any) -> T_co: pass

class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
def keys(self) -> Iterable[T]: pass # Approximate return type
def __getitem__(self, key: T) -> T_co: pass
@overload
def get(self, k: T) -> Optional[T_co]: pass
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/fixtures/typing-full.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class MutableSequence(Sequence[T]):
def __setitem__(self, n: Any, o: T) -> None: pass

class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
def keys(self) -> Iterable[T]: pass # Approximate return type
def __getitem__(self, key: T) -> T_co: pass
@overload
def get(self, k: T) -> Optional[T_co]: pass
Expand Down
5 changes: 4 additions & 1 deletion test-data/unit/fixtures/typing-namedtuple.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ Literal = 0
Optional = 0
Self = 0

T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
KT = TypeVar('KT')

class Iterable(Generic[T_co]): pass
class Iterator(Iterable[T_co]): pass
class Sequence(Iterable[T_co]): pass
class Mapping(Iterable[KT], Generic[KT, T_co]): pass
class Mapping(Iterable[KT], Generic[KT, T_co]):
def keys(self) -> Iterable[T]: pass # Approximate return type
def __getitem__(self, key: T) -> T_co: pass

class Tuple(Sequence): pass
class NamedTuple(Tuple):
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/lib-stub/_typeshed.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ _KT = TypeVar("_KT")
_VT_co = TypeVar("_VT_co", covariant=True)

class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
def keys(self) -> Iterable[_KT]: ...
def __getitem__(self, __key: _KT) -> _VT_co: ...
def keys(self) -> Iterable[_KT]: pass
def __getitem__(self, __key: _KT) -> _VT_co: pass
0