Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
# type-only import because of mutual dependence between these classes
from distutils.dist import Distribution

from typing_extensions import TypeVarTuple, Unpack
from typing_extensions import TypeVarTuple, Unpack, deprecated

_Ts = TypeVarTuple("_Ts")
else:

def deprecated(message):
return lambda fn: fn


_StrPathT = TypeVar("_StrPathT", bound="str | os.PathLike[str]")
_BytesPathT = TypeVar("_BytesPathT", bound="bytes | os.PathLike[bytes]")
Expand Down Expand Up @@ -322,11 +327,18 @@ def set_undefined_options(
if getattr(self, dst_option) is None:
setattr(self, dst_option, getattr(src_cmd_obj, src_option))

@overload
def get_finalized_command(self, command: str, create: None = None) -> Command: ...
@deprecated("The 'create' argument is deprecated and doesn't do anything.")
@overload
def get_finalized_command(self, command: str, create: bool) -> Command: ...
# NOTE: Because distutils is private to Setuptools and not all commands are exposed here,
# not every possible command is enumerated in the signature.
def get_finalized_command(self, command: str, create: bool = True) -> Command:
def get_finalized_command(
self, command: str, create: bool | None = None
) -> Command:
"""Wrapper around Distribution's 'get_command_obj()' method: find
(create if necessary and 'create' is true) the command object for
(create if necessary) the command object for
'command', call its 'ensure_finalized()' method, and return the
finalized command object.
"""
Expand Down
2 changes: 1 addition & 1 deletion distutils/compilers/C/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Compiler:
# dictionary (see below -- used by the 'new_compiler()' factory
# function) -- authors of new compiler interface classes are
# responsible for updating 'compiler_class'!
compiler_type: ClassVar[str] = None # type: ignore[assignment]
compiler_type: ClassVar[str] = None

# XXX things not handled by this compiler abstraction model:
# * client can't provide additional options for a compiler,
Expand Down
33 changes: 20 additions & 13 deletions distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@

if TYPE_CHECKING:
from _typeshed import SupportsWrite
from typing_extensions import TypeAlias
from typing_extensions import TypeAlias, deprecated

# type-only import because of mutual dependence between these modules
from .cmd import Command
from .extension import Extension
else:

def deprecated(message):
return lambda fn: fn


_CommandT = TypeVar("_CommandT", bound="Command")
_OptionsList: TypeAlias = list[
Expand Down Expand Up @@ -861,25 +866,27 @@ def get_command_class(self, command: str) -> type[Command]:
raise DistutilsModuleError(f"invalid command '{command}'")

@overload
def get_command_obj(
self, command: str, create: Literal[True] = True
) -> Command: ...
def get_command_obj(self, command: str, create: None = None) -> Command: ...
@deprecated("The 'create' argument is deprecated and doesn't do anything.")
@overload
def get_command_obj(
self, command: str, create: Literal[False]
) -> Command | None: ...
def get_command_obj(self, command: str, create: bool = True) -> Command | None:
def get_command_obj(self, command: str, create: bool) -> Command: ...
def get_command_obj(self, command: str, create: object = None) -> Command | None:
"""Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
object for 'command' is in the cache, then we either create and
return it (if 'create' is true) or return None.
object for 'command' is in the cache, then we create and
return it.
"""
if create is not None:
warnings.warn(
"The 'create' argument is deprecated and doesn't do anything.",
DeprecationWarning,
stacklevel=2,
)
cmd_obj = self.command_obj.get(command)
if not cmd_obj and create:
if not cmd_obj:
if DEBUG:
self.announce(
"Distribution.get_command_obj(): "
f"creating '{command}' command object"
f"Distribution.get_command_obj(): creating '{command}' command object"
)

klass = self.get_command_class(command)
Expand Down
Loading