Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit bd4e907

Browse files
authored
Merge branch 'python:master' into master
2 parents 24cedfa + f69f711 commit bd4e907

File tree

142 files changed

+1044
-674
lines changed

Some content is hidden

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

142 files changed

+1044
-674
lines changed

.github/workflows/daily.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
fail-fast: false
2626

2727
steps:
28-
- uses: actions/checkout@v2
28+
- uses: actions/checkout@v3
2929
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
30-
uses: actions/setup-python@v2
30+
uses: actions/setup-python@v4
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
- name: Update pip
@@ -46,8 +46,8 @@ jobs:
4646
shard-index: [0, 1, 2, 3]
4747
fail-fast: false
4848
steps:
49-
- uses: actions/checkout@v2
50-
- uses: actions/setup-python@v2
49+
- uses: actions/checkout@v3
50+
- uses: actions/setup-python@v4
5151
with:
5252
python-version: 3.9
5353
- name: Install dependencies
@@ -68,7 +68,7 @@ jobs:
6868
permissions:
6969
issues: write
7070
steps:
71-
- uses: actions/github-script@v5
71+
- uses: actions/github-script@v6
7272
with:
7373
github-token: ${{ secrets.GITHUB_TOKEN }}
7474
script: |

.github/workflows/mypy_primer.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
shard-index: [0, 1, 2, 3]
2222
fail-fast: false
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
with:
2626
path: typeshed_to_test
2727
fetch-depth: 0
28-
- uses: actions/setup-python@v2
28+
- uses: actions/setup-python@v4
2929
with:
3030
python-version: "3.10"
3131
- name: Install dependencies
@@ -54,7 +54,7 @@ jobs:
5454
| tee diff_${{ matrix.shard-index }}.txt
5555
) || [ $? -eq 1 ]
5656
- name: Upload mypy_primer diff
57-
uses: actions/upload-artifact@v2
57+
uses: actions/upload-artifact@v3
5858
with:
5959
name: mypy_primer_diffs
6060
path: diff_${{ matrix.shard-index }}.txt
@@ -64,7 +64,7 @@ jobs:
6464
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
6565
- if: ${{ matrix.shard-index }} == 0
6666
name: Upload PR number
67-
uses: actions/upload-artifact@v2
67+
uses: actions/upload-artifact@v3
6868
with:
6969
name: mypy_primer_diffs
7070
path: pr_number.txt

.github/workflows/mypy_primer_comment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Download diffs
20-
uses: actions/github-script@v5
20+
uses: actions/github-script@v6
2121
with:
2222
script: |
2323
const fs = require('fs');
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: Post comment
4545
id: post-comment
46-
uses: actions/github-script@v5
46+
uses: actions/github-script@v6
4747
with:
4848
github-token: ${{secrets.GITHUB_TOKEN}}
4949
script: |

.github/workflows/stubtest_stdlib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
fail-fast: false
3232

3333
steps:
34-
- uses: actions/checkout@v2
34+
- uses: actions/checkout@v3
3535
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
36-
uses: actions/setup-python@v2
36+
uses: actions/setup-python@v4
3737
with:
3838
python-version: ${{ matrix.python-version }}
3939
- name: Update pip

.github/workflows/tests.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,40 @@ jobs:
2121
name: Check file consistency
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
25-
- uses: actions/setup-python@v2
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-python@v4
26+
with:
27+
python-version: 3.x
2628
- run: pip install $(grep tomli== requirements-tests.txt)
2729
- run: ./tests/check_consistent.py
2830

2931
new-syntax:
3032
name: Ensure new syntax usage
3133
runs-on: ubuntu-latest
3234
steps:
33-
- uses: actions/checkout@v2
34-
- uses: actions/setup-python@v2
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-python@v4
37+
with:
38+
python-version: 3.x
3539
- run: ./tests/check_new_syntax.py
3640

3741
flake8:
3842
name: Lint with flake8
3943
runs-on: ubuntu-latest
4044
steps:
41-
- uses: actions/checkout@v2
42-
- uses: actions/setup-python@v2
45+
- uses: actions/checkout@v3
46+
- uses: actions/setup-python@v4
47+
with:
48+
python-version: 3.x
4349
- run: pip install $(grep flake8 requirements-tests.txt)
4450
- run: flake8
4551

4652
pytype:
4753
name: Run pytype against the stubs
4854
runs-on: ubuntu-latest
4955
steps:
50-
- uses: actions/checkout@v2
51-
- uses: actions/setup-python@v2
56+
- uses: actions/checkout@v3
57+
- uses: actions/setup-python@v4
5258
with:
5359
python-version: "3.10"
5460
- run: pip install -r requirements-tests.txt
@@ -63,8 +69,10 @@ jobs:
6369
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
6470
fail-fast: false
6571
steps:
66-
- uses: actions/checkout@v2
67-
- uses: actions/setup-python@v2
72+
- uses: actions/checkout@v3
73+
- uses: actions/setup-python@v4
74+
with:
75+
python-version: 3.x
6876
- run: pip install $(grep tomli== requirements-tests.txt) $(grep mypy== requirements-tests.txt) termcolor
6977
- run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
7078

@@ -79,7 +87,7 @@ jobs:
7987
env:
8088
PYRIGHT_VERSION: 1.1.255 # Must match pyright_test.py.
8189
steps:
82-
- uses: actions/checkout@v2
90+
- uses: actions/checkout@v3
8391
- uses: jakebailey/pyright-action@v1
8492
with:
8593
version: ${{ env.PYRIGHT_VERSION }}
@@ -99,10 +107,10 @@ jobs:
99107
runs-on: ubuntu-20.04
100108
if: github.event_name == 'pull_request'
101109
steps:
102-
- uses: actions/checkout@v2
110+
- uses: actions/checkout@v3
103111
with:
104112
fetch-depth: 0
105-
- uses: actions/setup-python@v2
113+
- uses: actions/setup-python@v4
106114
with:
107115
python-version: 3.9
108116
- name: Install dependencies

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mypy==0.960
2-
pytype==2022.6.6; platform_system != "Windows"
2+
pytype==2022.6.23; platform_system != "Windows"
33
# must match .pre-commit-config.yaml
44
black==22.3.0
55
# must match .pre-commit-config.yaml

scripts/create_baseline_stubs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ def main() -> None:
139139
# The importlib.metadata module is used for projects whose name is different
140140
# from the runtime Python package name (example: PyYAML/yaml)
141141
if sys.version_info >= (3, 8):
142-
packages = [name for name in distribution(project).read_text("top_level.txt").split() if not name.startswith("_")]
143-
if len(packages) == 1:
144-
package = packages[0]
142+
dist = distribution(project).read_text("top_level.txt")
143+
if dist is not None:
144+
packages = [name for name in dist.split() if not name.startswith("_")]
145+
if len(packages) == 1:
146+
package = packages[0]
145147
print(f'Using detected package "{package}" for project "{project}"', file=sys.stderr)
146148
print("Suggestion: Try again with --package argument if that's not what you wanted", file=sys.stderr)
147149

scripts/stubsabot.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
import zipfile
1717
from dataclasses import dataclass
1818
from pathlib import Path
19-
from typing import Any
19+
from typing import Any, TypeVar
2020

2121
import aiohttp
2222
import packaging.specifiers
2323
import packaging.version
2424
import tomli
2525
import tomlkit
2626

27+
ActionLevelSelf = TypeVar("ActionLevelSelf", bound="ActionLevel")
28+
2729

2830
class ActionLevel(enum.IntEnum):
29-
def __new__(cls, value: int, doc: str):
31+
def __new__(cls: type[ActionLevelSelf], value: int, doc: str) -> ActionLevelSelf:
3032
member = int.__new__(cls, value)
3133
member._value_ = value
3234
member.__doc__ = doc
@@ -64,6 +66,7 @@ class PypiInfo:
6466
# https://warehouse.pypa.io/api-reference/json.html#get--pypi--project_name--json
6567
# Corresponds to a single entry from `releases` for the given version
6668
release_to_download: dict[str, Any]
69+
info: dict[str, Any]
6770

6871

6972
async def fetch_pypi_info(distribution: str, session: aiohttp.ClientSession) -> PypiInfo:
@@ -80,6 +83,7 @@ async def fetch_pypi_info(distribution: str, session: aiohttp.ClientSession) ->
8083
version=packaging.version.Version(version),
8184
upload_date=date,
8285
release_to_download=release_to_download,
86+
info=j["info"],
8387
)
8488

8589

@@ -89,6 +93,7 @@ class Update:
8993
stub_path: Path
9094
old_version_spec: str
9195
new_version_spec: str
96+
links: dict[str, str]
9297

9398
def __str__(self) -> str:
9499
return f"Updating {self.distribution} from {self.old_version_spec!r} to {self.new_version_spec!r}"
@@ -100,6 +105,7 @@ class Obsolete:
100105
stub_path: Path
101106
obsolete_since_version: str
102107
obsolete_since_date: datetime.datetime
108+
links: dict[str, str]
103109

104110
def __str__(self) -> str:
105111
return f"Marking {self.distribution} as obsolete since {self.obsolete_since_version!r}"
@@ -171,35 +177,45 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
171177
if pypi_info.version in spec:
172178
return NoUpdate(stub_info.distribution, "up to date")
173179

180+
project_urls = pypi_info.info["project_urls"] or {}
181+
maybe_links: dict[str, str | None] = {
182+
"Release": pypi_info.info["release_url"],
183+
"Homepage": project_urls.get("Homepage"),
184+
"Changelog": project_urls.get("Changelog") or project_urls.get("Changes") or project_urls.get("Change Log"),
185+
}
186+
links = {k: v for k, v in maybe_links.items() if v is not None}
187+
174188
if await package_contains_py_typed(pypi_info.release_to_download, session):
175189
return Obsolete(
176190
stub_info.distribution,
177191
stub_path,
178192
obsolete_since_version=str(pypi_info.version),
179193
obsolete_since_date=pypi_info.upload_date,
194+
links=links,
180195
)
181196

182197
return Update(
183198
distribution=stub_info.distribution,
184199
stub_path=stub_path,
185200
old_version_spec=stub_info.version_spec,
186201
new_version_spec=get_updated_version_spec(stub_info.version_spec, pypi_info.version),
202+
links=links,
187203
)
188204

189205

190206
TYPESHED_OWNER = "python"
191207

192208

193209
@functools.lru_cache()
194-
def get_origin_owner():
210+
def get_origin_owner() -> str:
195211
output = subprocess.check_output(["git", "remote", "get-url", "origin"], text=True)
196212
match = re.search(r"([email protected]:|https://github.com/)(?P<owner>[^/]+)/(?P<repo>[^/]+).git", output)
197213
assert match is not None
198214
assert match.group("repo") == "typeshed"
199215
return match.group("owner")
200216

201217

202-
async def create_or_update_pull_request(*, title: str, body: str, branch_name: str, session: aiohttp.ClientSession):
218+
async def create_or_update_pull_request(*, title: str, body: str, branch_name: str, session: aiohttp.ClientSession) -> None:
203219
secret = os.environ["GITHUB_TOKEN"]
204220
if secret.startswith("ghp"):
205221
auth = f"token {secret}"
@@ -266,7 +282,9 @@ async def suggest_typeshed_update(update: Update, session: aiohttp.ClientSession
266282
return
267283
subprocess.check_call(["git", "push", "origin", branch_name, "--force-with-lease"])
268284

269-
body = """\
285+
body = "\n".join(f"{k}: {v}" for k, v in update.links.items())
286+
body += """
287+
270288
If stubtest fails for this PR:
271289
- Leave this PR open (as a reminder, and to prevent stubsabot from opening another PR)
272290
- Fix stubtest failures in another PR, then close this PR
@@ -293,7 +311,8 @@ async def suggest_typeshed_obsolete(obsolete: Obsolete, session: aiohttp.ClientS
293311
return
294312
subprocess.check_call(["git", "push", "origin", branch_name, "--force-with-lease"])
295313

296-
await create_or_update_pull_request(title=title, body="", branch_name=branch_name, session=session)
314+
body = "\n".join(f"{k}: {v}" for k, v in obsolete.links.items())
315+
await create_or_update_pull_request(title=title, body=body, branch_name=branch_name, session=session)
297316

298317

299318
async def main() -> None:

stdlib/@python2/itertools.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class chain(Iterator[_T], Generic[_T]):
2222

2323
def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ...
2424
def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
25-
def ifilter(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
25+
@overload
26+
def ifilter(predicate: None, iterable: Iterable[_T | None]) -> Iterator[_T]: ...
27+
@overload
28+
def ifilter(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
2629
def ifilterfalse(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
2730
@overload
2831
def groupby(iterable: Iterable[_T], key: None = ...) -> Iterator[tuple[_T, Iterator[_T]]]: ...

stdlib/_decimal.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from _typeshed import Self
44
from collections.abc import Container, Sequence
55
from types import TracebackType
6-
from typing import Any, NamedTuple, Union, overload
6+
from typing import Any, ClassVar, NamedTuple, Union, overload
77
from typing_extensions import TypeAlias
88

99
_Decimal: TypeAlias = Decimal | int
@@ -209,7 +209,8 @@ class Context:
209209
def clear_traps(self) -> None: ...
210210
def copy(self) -> Context: ...
211211
def __copy__(self) -> Context: ...
212-
__hash__: Any
212+
# see https://github.com/python/cpython/issues/94107
213+
__hash__: ClassVar[None] # type: ignore[assignment]
213214
def Etiny(self) -> int: ...
214215
def Etop(self) -> int: ...
215216
def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ...

stdlib/_dummy_threading.pyi

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import sys
2+
from _typeshed import ProfileFunction, TraceFunction
23
from collections.abc import Callable, Iterable, Mapping
3-
from types import FrameType, TracebackType
4+
from types import TracebackType
45
from typing import Any, TypeVar
5-
from typing_extensions import TypeAlias
66

7-
# TODO recursive type
8-
_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None]
9-
10-
_PF: TypeAlias = Callable[[FrameType, str, Any], None]
117
_T = TypeVar("_T")
128

139
__all__ = [
@@ -43,8 +39,8 @@ def currentThread() -> Thread: ...
4339
def get_ident() -> int: ...
4440
def enumerate() -> list[Thread]: ...
4541
def main_thread() -> Thread: ...
46-
def settrace(func: _TF) -> None: ...
47-
def setprofile(func: _PF | None) -> None: ...
42+
def settrace(func: TraceFunction) -> None: ...
43+
def setprofile(func: ProfileFunction | None) -> None: ...
4844
def stack_size(size: int = ...) -> int: ...
4945

5046
TIMEOUT_MAX: float

0 commit comments

Comments
 (0)