-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Merge typeshed return annotations #4744
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
abravalheri
merged 3 commits into
pypa:main
from
Avasam:Merge-typeshed-return-annotations
May 29, 2025
+114
−81
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,21 @@ | |
import re | ||
import sys | ||
import textwrap | ||
from collections.abc import Iterator | ||
from sysconfig import get_path, get_platform, get_python_version | ||
from types import CodeType | ||
from typing import TYPE_CHECKING, Literal | ||
from typing import TYPE_CHECKING, AnyStr, Literal | ||
|
||
from setuptools import Command | ||
from setuptools.extension import Library | ||
|
||
from .._path import StrPathT, ensure_directory | ||
from .._path import StrPath, StrPathT, ensure_directory | ||
|
||
from distutils import log | ||
from distutils.dir_util import mkpath, remove_tree | ||
|
||
if TYPE_CHECKING: | ||
from _typeshed import GenericPath | ||
from typing_extensions import TypeAlias | ||
|
||
# Same as zipfile._ZipFileMode from typeshed | ||
|
@@ -40,7 +42,9 @@ def strip_module(filename): | |
return filename | ||
|
||
|
||
def sorted_walk(dir): | ||
def sorted_walk( | ||
dir: GenericPath[AnyStr], | ||
) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: | ||
"""Do os.walk in a reproducible way, | ||
independent of indeterministic filesystem readdir order | ||
""" | ||
|
@@ -161,7 +165,7 @@ def call_command(self, cmdname, **kw): | |
self.run_command(cmdname) | ||
return cmd | ||
|
||
def run(self): # noqa: C901 # is too complex (14) # FIXME | ||
def run(self) -> None: # noqa: C901 # is too complex (14) # FIXME | ||
# Generate metadata first | ||
self.run_command("egg_info") | ||
# We run install_lib before install_data, because some data hacks | ||
|
@@ -232,7 +236,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME | |
self.egg_output, | ||
archive_root, | ||
verbose=self.verbose, | ||
dry_run=self.dry_run, | ||
dry_run=self.dry_run, # type: ignore[arg-type] # Is an actual boolean in vendored _distutils | ||
mode=self.gen_header(), | ||
) | ||
if not self.keep_temp: | ||
|
@@ -245,7 +249,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME | |
self.egg_output, | ||
)) | ||
|
||
def zap_pyfiles(self): | ||
def zap_pyfiles(self) -> None: | ||
log.info("Removing .py files from temporary directory") | ||
for base, dirs, files in walk_egg(self.bdist_dir): | ||
for name in files: | ||
|
@@ -260,6 +264,8 @@ def zap_pyfiles(self): | |
|
||
pattern = r'(?P<name>.+)\.(?P<magic>[^.]+)\.pyc' | ||
m = re.match(pattern, name) | ||
# We shouldn't find any non-pyc files in __pycache__ | ||
assert m is not None | ||
Comment on lines
+267
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly an annotation change, but I included it here because it didn't feel worth doing a PR just for this |
||
path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc') | ||
log.info(f"Renaming file from [{path_old}] to [{path_new}]") | ||
try: | ||
|
@@ -323,7 +329,7 @@ def get_ext_outputs(self): | |
NATIVE_EXTENSIONS: dict[str, None] = dict.fromkeys('.dll .so .dylib .pyd'.split()) | ||
|
||
|
||
def walk_egg(egg_dir): | ||
def walk_egg(egg_dir: StrPath) -> Iterator[tuple[str, list[str], list[str]]]: | ||
"""Walk an unpacked egg's contents, skipping the metadata directory""" | ||
walker = sorted_walk(egg_dir) | ||
base, dirs, files = next(walker) | ||
|
@@ -409,7 +415,7 @@ def scan_module(egg_dir, base, name, stubs): | |
return safe | ||
|
||
|
||
def iter_symbols(code): | ||
def iter_symbols(code: CodeType) -> Iterator[str]: | ||
"""Yield names and strings used by `code` and its nested code objects""" | ||
yield from code.co_names | ||
for const in code.co_consts: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.