GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — allow arbitrary types in set difference (#15160) · python/typeshed@236a8c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • stdlib
    • @tests/test_cases/builtins
      • check_set.py
    • builtins.pyi
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎stdlib/@tests/test_cases/builtins/check_set.py‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing_extensions import Literal, assert_type
2+
3+
4+
# Note: type checkers / linters are free to point out that the set difference
5+
# below is redundant. But typeshed should allow it, as its job is to describe
6+
# what is legal in Python, not what is sensible.
7+
# For instance, set[Literal] - set[str] should be legal.
8+
def test_set_difference(x: set[Literal["foo", "bar"]], y: set[str], z: set[int]) -> None:
9+
assert_type(x - y, set[Literal["foo", "bar"]])
10+
assert_type(y - x, set[str])
11+
assert_type(x - z, set[Literal["foo", "bar"]])
12+
assert_type(z - x, set[int])
13+
assert_type(y - z, set[str])
14+
assert_type(z - y, set[int])
Collapse file

‎stdlib/builtins.pyi‎

Copy file name to clipboardExpand all lines: stdlib/builtins.pyi
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ class set(MutableSet[_T]):
12821282
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
12831283
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
12841284
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1285-
def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ...
1285+
def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
12861286
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
12871287
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
12881288
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
@@ -1313,7 +1313,7 @@ class frozenset(AbstractSet[_T_co]):
13131313
def __iter__(self) -> Iterator[_T_co]: ...
13141314
def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
13151315
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1316-
def __sub__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
1316+
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
13171317
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
13181318
def __le__(self, value: AbstractSet[object], /) -> bool: ...
13191319
def __lt__(self, value: AbstractSet[object], /) -> bool: ...

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.