Skip to content

Commit d266359

Browse files
jaracoAvasam
authored andcommitted
Merge branch 'main' into Ruff-0.8.0-UP031-manual-fixes
2 parents a88eace + c375e92 commit d266359

15 files changed

+86
-117
lines changed

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _save_cwd():
4848

4949
@pytest.fixture
5050
def distutils_managed_tempdir(request):
51-
from distutils.tests.compat import py38 as os_helper
51+
from distutils.tests.compat import py39 as os_helper
5252

5353
self = request.instance
5454
self.tempdirs = []

distutils/cmd.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
in the distutils.command package.
55
"""
66

7+
from __future__ import annotations
8+
79
import logging
810
import os
911
import re
1012
import sys
13+
from typing import TypeVar, overload
1114

1215
from . import _modified, archive_util, dir_util, file_util, util
1316
from ._log import log
1417
from .errors import DistutilsOptionError
1518

19+
_CommandT = TypeVar("_CommandT", bound="Command")
20+
1621

1722
class Command:
1823
"""Abstract base class for defining command classes, the "worker bees"
@@ -305,7 +310,17 @@ def get_finalized_command(self, command, create=True):
305310

306311
# XXX rename to 'get_reinitialized_command()'? (should do the
307312
# same in dist.py, if so)
308-
def reinitialize_command(self, command, reinit_subcommands=False):
313+
@overload
314+
def reinitialize_command(
315+
self, command: str, reinit_subcommands: bool = False
316+
) -> Command: ...
317+
@overload
318+
def reinitialize_command(
319+
self, command: _CommandT, reinit_subcommands: bool = False
320+
) -> _CommandT: ...
321+
def reinitialize_command(
322+
self, command: str | Command, reinit_subcommands=False
323+
) -> Command:
309324
return self.distribution.reinitialize_command(command, reinit_subcommands)
310325

311326
def run_command(self, command):

distutils/compat/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from .py38 import removeprefix
4-
53

64
def consolidate_linker_args(args: list[str]) -> list[str] | str:
75
"""
@@ -12,4 +10,4 @@ def consolidate_linker_args(args: list[str]) -> list[str] | str:
1210

1311
if not all(arg.startswith('-Wl,') for arg in args):
1412
return args
15-
return '-Wl,' + ','.join(removeprefix(arg, '-Wl,') for arg in args)
13+
return '-Wl,' + ','.join(arg.removeprefix('-Wl,') for arg in args)

distutils/compat/py38.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

distutils/dist.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
being built/installed/distributed.
55
"""
66

7+
from __future__ import annotations
8+
79
import contextlib
810
import logging
911
import os
@@ -13,6 +15,7 @@
1315
import warnings
1416
from collections.abc import Iterable
1517
from email import message_from_file
18+
from typing import TYPE_CHECKING, TypeVar, overload
1619

1720
from packaging.utils import canonicalize_name, canonicalize_version
1821

@@ -27,6 +30,11 @@
2730
from .fancy_getopt import FancyGetopt, translate_longopt
2831
from .util import check_environ, rfc822_escape, strtobool
2932

33+
if TYPE_CHECKING:
34+
from .cmd import Command
35+
36+
_CommandT = TypeVar("_CommandT", bound="Command")
37+
3038
# Regex to define acceptable Distutils command names. This is not *quite*
3139
# the same as a Python NAME -- I don't allow leading underscores. The fact
3240
# that they're very similar is no coincidence; the default naming scheme is
@@ -900,7 +908,17 @@ def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
900908
except ValueError as msg:
901909
raise DistutilsOptionError(msg)
902910

903-
def reinitialize_command(self, command, reinit_subcommands=False):
911+
@overload
912+
def reinitialize_command(
913+
self, command: str, reinit_subcommands: bool = False
914+
) -> Command: ...
915+
@overload
916+
def reinitialize_command(
917+
self, command: _CommandT, reinit_subcommands: bool = False
918+
) -> _CommandT: ...
919+
def reinitialize_command(
920+
self, command: str | Command, reinit_subcommands=False
921+
) -> Command:
904922
"""Reinitializes a command to the state it was in when first
905923
returned by 'get_command_obj()': ie., initialized but not yet
906924
finalized. This provides the opportunity to sneak option

distutils/tests/compat/py38.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

distutils/tests/compat/py39.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
3+
if sys.version_info >= (3, 10):
4+
from test.support.import_helper import (
5+
CleanImport as CleanImport,
6+
)
7+
from test.support.import_helper import (
8+
DirsOnSysPath as DirsOnSysPath,
9+
)
10+
from test.support.os_helper import (
11+
EnvironmentVarGuard as EnvironmentVarGuard,
12+
)
13+
from test.support.os_helper import (
14+
rmtree as rmtree,
15+
)
16+
from test.support.os_helper import (
17+
skip_unless_symlink as skip_unless_symlink,
18+
)
19+
from test.support.os_helper import (
20+
unlink as unlink,
21+
)
22+
else:
23+
from test.support import (
24+
CleanImport as CleanImport,
25+
)
26+
from test.support import (
27+
DirsOnSysPath as DirsOnSysPath,
28+
)
29+
from test.support import (
30+
EnvironmentVarGuard as EnvironmentVarGuard,
31+
)
32+
from test.support import (
33+
rmtree as rmtree,
34+
)
35+
from test.support import (
36+
skip_unless_symlink as skip_unless_symlink,
37+
)
38+
from test.support import (
39+
unlink as unlink,
40+
)

distutils/tests/test_bdist_rpm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from distutils.tests import support
99

1010
import pytest
11-
12-
from .compat.py38 import requires_zlib
11+
from test.support import requires_zlib
1312

1413
SETUP_PY = """\
1514
from distutils.core import setup

distutils/tests/test_build_ext.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@
1919
)
2020
from distutils.extension import Extension
2121
from distutils.tests import missing_compiler_executable
22-
from distutils.tests.support import (
23-
TempdirManager,
24-
copy_xxmodule_c,
25-
fixup_build_ext,
26-
)
22+
from distutils.tests.support import TempdirManager, copy_xxmodule_c, fixup_build_ext
2723
from io import StringIO
2824

2925
import jaraco.path
3026
import path
3127
import pytest
3228
from test import support
3329

34-
from .compat import py38 as import_helper
30+
from .compat import py39 as import_helper
3531

3632

3733
@pytest.fixture()

distutils/tests/test_extension.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from distutils.extension import Extension, read_setup_file
77

88
import pytest
9-
10-
from .compat.py38 import check_warnings
9+
from test.support.warnings_helper import check_warnings
1110

1211

1312
class TestExtension:

distutils/tests/test_filelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import jaraco.path
1111
import pytest
1212

13-
from .compat import py38 as os_helper
13+
from .compat import py39 as os_helper
1414

1515
MANIFEST_IN = """\
1616
include ok

distutils/tests/test_spawn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313
from test.support import unix_shell
1414

15-
from .compat import py38 as os_helper
15+
from .compat import py39 as os_helper
1616

1717

1818
class TestSpawn(support.TempdirManager):

distutils/tests/test_unixccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
from . import support
15-
from .compat.py38 import EnvironmentVarGuard
15+
from .compat.py39 import EnvironmentVarGuard
1616

1717

1818
@pytest.fixture(autouse=True)

distutils/util.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .spawn import spawn
2626

2727

28-
def get_host_platform():
28+
def get_host_platform() -> str:
2929
"""
3030
Return a string that identifies the current platform. Use this
3131
function to distinguish platform-specific build directories and
@@ -34,15 +34,7 @@ def get_host_platform():
3434

3535
# This function initially exposed platforms as defined in Python 3.9
3636
# even with older Python versions when distutils was split out.
37-
# Now it delegates to stdlib sysconfig, but maintains compatibility.
38-
39-
if sys.version_info < (3, 9):
40-
if os.name == "posix" and hasattr(os, 'uname'):
41-
osname, host, release, version, machine = os.uname()
42-
if osname[:3] == "aix":
43-
from .compat.py38 import aix_platform
44-
45-
return aix_platform(osname, version, release)
37+
# Now it delegates to stdlib sysconfig.
4638

4739
return sysconfig.get_platform()
4840

ruff.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ extend-select = [
1919
"YTT",
2020
]
2121
ignore = [
22-
# TODO: Fix these new violations in Ruff 0.8.0
23-
"UP031",
24-
"UP036",
25-
2622
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
2723
"W191",
2824
"E111",

0 commit comments

Comments
 (0)