Skip to content

Commit 01e8858

Browse files
committed
Explore deprecating create arg of get_command_obj and get_finalized_command
1 parent 603b94e commit 01e8858

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

distutils/cmd.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
# type-only import because of mutual dependence between these classes
2323
from distutils.dist import Distribution
2424

25-
from typing_extensions import TypeVarTuple, Unpack
25+
from typing_extensions import TypeVarTuple, Unpack, deprecated
2626

2727
_Ts = TypeVarTuple("_Ts")
28+
else:
29+
30+
def deprecated(message):
31+
return lambda fn: fn
32+
2833

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

330+
@overload
331+
def get_finalized_command(self, command: str, create: None = None) -> Command: ...
332+
@deprecated("The 'create' argument is deprecated and doesn't do anything.")
333+
@overload
334+
def get_finalized_command(self, command: str, create: bool) -> Command: ...
325335
# NOTE: Because distutils is private to Setuptools and not all commands are exposed here,
326336
# not every possible command is enumerated in the signature.
327-
def get_finalized_command(self, command: str, create: bool = True) -> Command:
337+
def get_finalized_command(
338+
self, command: str, create: bool | None = None
339+
) -> Command:
328340
"""Wrapper around Distribution's 'get_command_obj()' method: find
329-
(create if necessary and 'create' is true) the command object for
341+
(create if necessary) the command object for
330342
'command', call its 'ensure_finalized()' method, and return the
331343
finalized command object.
332344
"""

distutils/dist.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@
4141

4242
if TYPE_CHECKING:
4343
from _typeshed import SupportsWrite
44-
from typing_extensions import TypeAlias
44+
from typing_extensions import TypeAlias, deprecated
4545

4646
# type-only import because of mutual dependence between these modules
4747
from .cmd import Command
4848
from .extension import Extension
49+
else:
50+
51+
def deprecated(message):
52+
return lambda fn: fn
4953

5054
_CommandT = TypeVar("_CommandT", bound="Command")
5155
_OptionsList: TypeAlias = list[
@@ -861,25 +865,27 @@ def get_command_class(self, command: str) -> type[Command]:
861865
raise DistutilsModuleError(f"invalid command '{command}'")
862866

863867
@overload
864-
def get_command_obj(
865-
self, command: str, create: Literal[True] = True
866-
) -> Command: ...
868+
def get_command_obj(self, command: str, create: None = None) -> Command: ...
869+
@deprecated("The 'create' argument is deprecated and doesn't do anything.")
867870
@overload
868-
def get_command_obj(
869-
self, command: str, create: Literal[False]
870-
) -> Command | None: ...
871-
def get_command_obj(self, command: str, create: bool = True) -> Command | None:
871+
def get_command_obj(self, command: str, create: bool) -> Command: ...
872+
def get_command_obj(self, command: str, create: object = None) -> Command | None:
872873
"""Return the command object for 'command'. Normally this object
873874
is cached on a previous call to 'get_command_obj()'; if no command
874-
object for 'command' is in the cache, then we either create and
875-
return it (if 'create' is true) or return None.
875+
object for 'command' is in the cache, then we create and
876+
return it.
876877
"""
878+
if create is not None:
879+
warnings.warn(
880+
"The 'create' argument is deprecated and doesn't do anything.",
881+
DeprecationWarning,
882+
stacklevel=2,
883+
)
877884
cmd_obj = self.command_obj.get(command)
878-
if not cmd_obj and create:
885+
if not cmd_obj:
879886
if DEBUG:
880887
self.announce(
881-
"Distribution.get_command_obj(): "
882-
f"creating '{command}' command object"
888+
f"Distribution.get_command_obj(): creating '{command}' command object"
883889
)
884890

885891
klass = self.get_command_class(command)

0 commit comments

Comments
 (0)