-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import site | ||
import subprocess | ||
import sys | ||
from typing import cast | ||
|
||
from setuptools import Command | ||
from setuptools.warnings import SetuptoolsDeprecationWarning | ||
|
@@ -27,18 +28,20 @@ class develop(Command): | |
prefix = None | ||
index_url = None | ||
|
||
def run(self): | ||
cmd = ( | ||
def run(self) -> None: # type: ignore[override] # Not including easy_install's show_deprecation argument | ||
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. I am trying to understand this comment. Maybe it is also a left over from merge/rebase from a time that 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. Indeed, this type-ignore no longer applies. This used to break the Liskov Substitution Principle. |
||
# Casting because mypy doesn't understand bool mult conditionals | ||
cmd = cast( | ||
list[str], | ||
[sys.executable, '-m', 'pip', 'install', '-e', '.', '--use-pep517'] | ||
+ ['--target', self.install_dir] * bool(self.install_dir) | ||
+ ['--no-deps'] * self.no_deps | ||
+ ['--user'] * self.user | ||
+ ['--prefix', self.prefix] * bool(self.prefix) | ||
+ ['--index-url', self.index_url] * bool(self.index_url) | ||
+ ['--index-url', self.index_url] * bool(self.index_url), | ||
) | ||
subprocess.check_call(cmd) | ||
|
||
def initialize_options(self): | ||
def initialize_options(self) -> None: | ||
DevelopDeprecationWarning.emit() | ||
|
||
def finalize_options(self) -> None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.