Skip to content

Commit c83ac31

Browse files
authored
Merge branch 'main' into networkx-merge-from-python-type-stubs
2 parents 26c884f + 9fecaca commit c83ac31

File tree

208 files changed

+2654
-1200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+2654
-1200
lines changed

.github/workflows/daily.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ jobs:
5050
check-latest: true
5151
- name: Install dependencies
5252
run: pip install -r requirements-tests.txt
53-
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
54-
- name: Install mypy from git
55-
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
5653
- name: Run stubtest
5754
run: python tests/stubtest_stdlib.py
5855

.github/workflows/stubtest_stdlib.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,5 @@ jobs:
4646
check-latest: true
4747
- name: Install dependencies
4848
run: pip install -r requirements-tests.txt
49-
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
50-
- name: Install mypy from git
51-
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
5249
- name: Run stubtest
5350
run: python tests/stubtest_stdlib.py

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
args: [--fix=lf]
1212
- id: check-case-conflict
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.13.2 # must match requirements-tests.txt
14+
rev: v0.13.3 # must match requirements-tests.txt
1515
hooks:
1616
- id: ruff
1717
name: Run ruff on stubs, tests and scripts

CONTRIBUTING.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def foo(x: Incomplete | None) -> list[Incomplete]: ...
311311
### What to do when a project's documentation and implementation disagree
312312

313313
Type stubs are meant to be external type annotations for a given
314-
library. While they are useful documentation in its own merit, they
314+
library. While they are useful documentation in their own right, they
315315
augment the project's concrete implementation, not the project's
316316
documentation. Whenever you find them disagreeing, model the type
317317
information after the actual implementation and file an issue on the
@@ -436,28 +436,24 @@ following criteria is met:
436436
* the upstream package was declared or appears to be unmaintained, and
437437
retaining the stubs causes maintenance issues in typeshed.
438438

439-
If a package ships its own `py.typed` file, please follow these steps:
439+
Case 1: If a package ships its own `py.typed` file, please follow these steps:
440440

441-
1. Open an issue with the earliest month of removal in the subject.
442-
2. A maintainer will add the
443-
["stubs: removal" label](https://github.com/python/typeshed/labels/%22stubs%3A%20removal%22).
444-
3. Open a PR that sets the `obsolete_since` field in the `METADATA.toml`
445-
file to the first version of the package that shipped `py.typed`.
446-
4. After at least six months, open a PR to remove the stubs.
441+
1. Make sure **stubsabot** open a PR that sets the `obsolete_since` field in the
442+
`METADATA.toml` file to the first version of the package that shipped `py.typed`.
443+
2. After at least six months, make sure **stubsabot** open a PR to remove the stubs.
447444

448-
If third-party stubs should be removed for other reasons, please follow these
449-
steps:
445+
Case 2: If third-party stubs should be removed for other reasons, please follow
446+
these steps:
450447

451448
1. Open an issue explaining why the stubs should be removed.
452449
2. A maintainer will add the
453450
["stubs: removal" label](https://github.com/python/typeshed/labels/%22stubs%3A%20removal%22).
454451
3. Open a PR that sets the `no_longer_updated` field in the `METADATA.toml`
455452
file to `true`.
456-
4. When a new version of the package was automatically uploaded to PyPI
457-
(which can take up to a day), open a PR to remove the stubs.
453+
4. When a new version of the package was automatically uploaded to PyPI (which
454+
can take up to a day), make sure **stubsabot** open a PR to remove the stubs.
458455

459-
Don't forget to make sure the library is not in the [`pyrightconfig.stricter.json`](./pyrightconfig.stricter.json)
460-
exclusion list. If feeling kindly, please update [mypy](https://github.com/python/mypy/blob/master/mypy/stubinfo.py)
456+
If feeling kindly, please update [mypy](https://github.com/python/mypy/blob/master/mypy/stubinfo.py)
461457
for any stub obsoletions or removals.
462458

463459
### Marking PRs as "deferred"

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
## About
88

99
Typeshed contains external type annotations for the Python standard library
10-
and Python builtins, as well as third party packages as contributed by
10+
and Python builtins, as well as third-party packages that are contributed by
1111
people external to those projects.
1212

13-
This data can e.g. be used for static analysis, type checking, type inference,
13+
This data can, e.g., be used for static analysis, type checking, type inference,
1414
and autocompletion.
1515

1616
For information on how to use typeshed, read below. Information for
@@ -29,8 +29,8 @@ If you're just using a type checker (e.g. [mypy](https://github.com/python/mypy/
2929
[pyright](https://github.com/microsoft/pyright), or PyCharm's built-in type
3030
checker), as opposed to
3131
developing it, you don't need to interact with the typeshed repo at
32-
all: a copy of standard library part of typeshed is bundled with type checkers.
33-
And type stubs for third party packages and modules you are using can
32+
all: a copy of the standard library part of typeshed is bundled with type checkers.
33+
And type stubs for third-party packages and modules you are using can
3434
be installed from PyPI. For example, if you are using `html5lib` and `requests`,
3535
you can install the type stubs using
3636

@@ -70,7 +70,7 @@ package you're using, each with its own tradeoffs:
7070
type checking due to changes in the stubs.
7171

7272
Another risk of this strategy is that stubs often lag behind
73-
the package being stubbed. You might want to force the package being stubbed
73+
the package that is being stubbed. You might want to force the package being stubbed
7474
to a certain minimum version because it fixes a critical bug, but if
7575
correspondingly updated stubs have not been released, your type
7676
checking results may not be fully accurate.
@@ -119,6 +119,6 @@ a review of your type annotations or stubs outside of typeshed, head over to
119119
[our discussion forum](https://github.com/python/typing/discussions).
120120
For less formal discussion, try the typing chat room on
121121
[gitter.im](https://gitter.im/python/typing). Some typeshed maintainers
122-
are almost always present; feel free to find us there and we're happy
122+
are almost always present; feel free to find us there, and we're happy
123123
to chat. Substantive technical discussion will be directed to the
124124
issue tracker.

pyproject.toml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ exclude = [
2626
]
2727

2828
[tool.ruff.lint]
29+
future-annotations = true
2930
# Disable all rules on test cases by default:
3031
# test cases often deliberately contain code
3132
# that might not be considered idiomatic or modern.
@@ -69,15 +70,22 @@ select = [
6970
# Only include flake8-annotations rules that are autofixable. Otherwise leave this to mypy+pyright
7071
"ANN2",
7172
# Most refurb rules are in preview and can be opinionated,
72-
# consider them individually as they come out of preview (last check: 0.8.4)
73+
# consider them individually as they come out of preview (last check: 0.13.1)
7374
"FURB105", # Unnecessary empty string passed to `print`
75+
"FURB116", # Replace `{function_name}` call with `{display}`
76+
"FURB122", # Use of `{}.write` in a for loop
7477
"FURB129", # Instead of calling `readlines()`, iterate over file object directly
78+
"FURB132", # Use `{suggestion}` instead of `check` and `remove`
7579
"FURB136", # Replace `if` expression with `{min_max}` call
80+
"FURB157", # Verbose expression in `Decimal` constructor
81+
"FURB162", # Unnecessary timezone replacement with zero offset
82+
"FURB166", # Use of `int` with explicit `base={base}` after removing prefix
7683
"FURB167", # Use of regular expression alias `re.{}`
7784
"FURB168", # Prefer `is` operator over `isinstance` to check if an object is `None`
7885
"FURB169", # Compare the identities of `{object}` and None instead of their respective types
7986
"FURB177", # Prefer `Path.cwd()` over `Path().resolve()` for current-directory lookups
8087
"FURB187", # Use of assignment of `reversed` on list `{name}`
88+
"FURB188", # Prefer `str.removeprefix()` over conditionally replacing with slice.
8189
# Used for lint.flake8-import-conventions.aliases
8290
"ICN001", # `{name}` should be imported as `{asname}`
8391
# PYI: only enable rules that have autofixes and that we always want to fix (even manually),
@@ -89,6 +97,7 @@ select = [
8997
"PYI014", # Only simple default values allowed for arguments
9098
"PYI015", # Only simple default values allowed for assignments
9199
"PYI016", # Duplicate union member `{}`
100+
"PYI018", # Private `{type_var_like_kind}` `{type_var_like_name}` is never used
92101
"PYI019", # Methods like `{method_name}` should return `Self` instead of a custom `TypeVar`
93102
"PYI020", # Quoted annotations should not be included in stubs
94103
"PYI025", # Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin
@@ -99,7 +108,8 @@ select = [
99108
"PYI044", # `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
100109
"PYI055", # Multiple `type[T]` usages in a union. Combine them into one, e.g., `type[{union_str}]`.
101110
"PYI058", # Use `{return_type}` as the return value for simple `{method}` methods
102-
# "PYI061", # TODO: Enable when out of preview
111+
# "PYI059", # TODO: Add when dropping Python 3.9 support
112+
"PYI061", # Use `None` rather than `Literal[None]`
103113
"PYI062", # Duplicate literal member `{}`
104114
"PYI064", # `Final[Literal[{literal}]]` can be replaced with a bare Final
105115
# flake8-simplify, excluding rules that can reduce performance or readability due to long line formatting
@@ -124,6 +134,7 @@ select = [
124134
"SIM223", # Use `{expr}` instead of `{replaced}`
125135
"SIM300", # Yoda condition detected
126136
"SIM401", # Use `{contents}` instead of an if block
137+
"SIM905", # Consider using a list literal instead of `str.{}`
127138
"SIM910", # Use `{expected}` instead of `{actual}` (dict-get-with-none-default)
128139
"SIM911", # Use `{expected}` instead of `{actual}` (zip-dict-keys-and-values)
129140
# Don't include TC rules that create a TYPE_CHECKING block or stringifies annotations
@@ -159,7 +170,7 @@ ignore = [
159170
# see https://github.com/astral-sh/ruff/issues/6465
160171
"E721", # Do not compare types, use `isinstance()`
161172
# Highly opinionated, and it's often necessary to violate it
162-
"PLC0415", # `import` should be at the top-level of a file
173+
"PLC0415", # `import` should be at the top-level of a file
163174
# Leave the size and complexity of tests to human interpretation
164175
"PLR09", # Too many ...
165176
# Too many magic number "2" that are preferable inline. https://github.com/astral-sh/ruff/issues/10009
@@ -175,9 +186,6 @@ ignore = [
175186
"TD003", # Missing issue link for this TODO
176187
# Mostly from scripts and tests, it's ok to have messages passed directly to exceptions
177188
"TRY003", # Avoid specifying long messages outside the exception class
178-
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
179-
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
180-
"PLC0205", # Sometimes __slots__ really is a string at runtime
181189
###
182190
# False-positives, but already checked by type-checkers
183191
###
@@ -208,6 +216,8 @@ ignore = [
208216
# Most pep8-naming rules don't apply for third-party stubs like typeshed.
209217
# N811 to N814 could apply, but we often use them to disambiguate a name whilst making it look like a more common one
210218
"N8", # pep8-naming
219+
# Sometimes __slots__ really is a string at runtime
220+
"PLC0205", # Class `__slots__` should be a non-string iterable
211221
# Stubs are allowed to use private variables (pyright's reportPrivateUsage is also disabled)
212222
"PLC2701", # Private name import from external module
213223
# Names in stubs should match implementation

pyrightconfig.stricter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@
8888
"stubs/seaborn",
8989
"stubs/setuptools/setuptools",
9090
"stubs/shapely",
91+
"stubs/simple-websocket",
9192
"stubs/tensorflow",
9293
"stubs/tqdm",
9394
"stubs/vobject",
9495
"stubs/workalendar",
96+
"stubs/xmldiff",
9597
],
9698
"typeCheckingMode": "strict",
9799
// TODO: Complete incomplete stubs

requirements-tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Type checkers that we test our stubs against. These should always
22
# be pinned to a specific version to make failure reproducible.
33
mypy==1.18.2
4-
pyright==1.1.406
4+
pyright==1.1.407
55

66
# Libraries used by our various scripts.
77
aiohttp==3.12.15
@@ -19,7 +19,7 @@ termcolor>=2.3
1919
tomli==2.2.1; python_version < "3.11"
2020
tomlkit==0.13.3
2121
typing_extensions>=4.15.0rc1
22-
uv==0.8.22
22+
uv==0.9.6
2323

2424
# Utilities for typeshed infrastructure scripts.
2525
ts_utils @ file:lib

scripts/stubsabot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __str__(self) -> str:
161161
@dataclass
162162
class Remove:
163163
distribution: str
164-
reason: str
164+
reason: Literal["ships py.typed file", "unmaintained"]
165165
links: dict[str, str]
166166

167167
def __str__(self) -> str:
@@ -171,7 +171,7 @@ def __str__(self) -> str:
171171
@dataclass
172172
class NoUpdate:
173173
distribution: str
174-
reason: str
174+
reason: Literal["obsolete", "no longer updated", "up to date"]
175175

176176
def __str__(self) -> str:
177177
return f"{colored('skipping', 'green')} ({self.reason})"
@@ -642,7 +642,7 @@ async def determine_action_no_error_handling(
642642
"Typeshed release": f"{pypi_info.pypi_root}",
643643
"Typeshed stubs": f"https://github.com/{TYPESHED_OWNER}/typeshed/tree/main/stubs/{stub_info.distribution}",
644644
}
645-
return Remove(stub_info.distribution, reason="older than 6 months", links=links)
645+
return Remove(stub_info.distribution, reason="ships py.typed file", links=links)
646646
else:
647647
return NoUpdate(stub_info.distribution, "obsolete")
648648
if stub_info.no_longer_updated:
@@ -654,7 +654,7 @@ async def determine_action_no_error_handling(
654654
"Typeshed release": f"{pypi_info.pypi_root}",
655655
"Typeshed stubs": f"https://github.com/{TYPESHED_OWNER}/typeshed/tree/main/stubs/{stub_info.distribution}",
656656
}
657-
return Remove(stub_info.distribution, reason="no longer updated", links=links)
657+
return Remove(stub_info.distribution, reason="unmaintained", links=links)
658658
else:
659659
return NoUpdate(stub_info.distribution, "no longer updated")
660660

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ sys.ps1 # Available in interactive mode
170170
sys.ps2 # Available in interactive mode
171171
sys.tracebacklimit # Must be set first
172172

173+
# This is only present if Python was built with zlib-ng.
174+
(zlib\.ZLIBNG_VERSION)?
175+
(compression\.zlib\.ZLIBNG_VERSION)?
176+
173177

174178
# ==========================================================
175179
# Other allowlist entries that cannot or should not be fixed
@@ -233,7 +237,6 @@ asyncio.locks.Condition.release
233237
builtins.memoryview.__contains__ # C type that implements __getitem__
234238
builtins.reveal_locals # Builtins that type checkers pretends exist
235239
builtins.reveal_type # Builtins that type checkers pretends exist
236-
builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute.
237240

238241
# The following CodecInfo properties are added in __new__
239242
codecs.CodecInfo.decode

0 commit comments

Comments
 (0)