Skip to content

Commit 2ab5dd5

Browse files
committed
Explore deprecating create arg of get_command_obj and get_finalized_command
1 parent 9a58c2a commit 2ab5dd5

2 files changed

Lines changed: 35 additions & 15 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]")
@@ -306,11 +311,18 @@ def set_undefined_options(
306311
if getattr(self, dst_option) is None:
307312
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
308313

314+
@overload
315+
def get_finalized_command(self, command: str, create: None = None) -> Command: ...
316+
@deprecated("The 'create' argument is deprecated and doesn't do anything.")
317+
@overload
318+
def get_finalized_command(self, command: str, create: bool) -> Command: ...
309319
# NOTE: Because distutils is private to Setuptools and not all commands are exposed here,
310320
# not every possible command is enumerated in the signature.
311-
def get_finalized_command(self, command: str, create: bool = True) -> Command:
321+
def get_finalized_command(
322+
self, command: str, create: bool | None = None
323+
) -> Command:
312324
"""Wrapper around Distribution's 'get_command_obj()' method: find
313-
(create if necessary and 'create' is true) the command object for
325+
(create if necessary) the command object for
314326
'command', call its 'ensure_finalized()' method, and return the
315327
finalized command object.
316328
"""

distutils/dist.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@
4242
from typing import TypeAlias
4343

4444
from _typeshed import SupportsWrite
45+
from typing_extensions import deprecated
4546

4647
# type-only import because of mutual dependence between these modules
4748
from .cmd import Command
4849
from .extension import Extension
50+
else:
51+
52+
def deprecated(message):
53+
return lambda fn: fn
54+
4955

5056
_CommandT = TypeVar("_CommandT", bound="Command")
5157
_OptionsList: TypeAlias = list[
@@ -859,25 +865,27 @@ def get_command_class(self, command: str) -> type[Command]:
859865
raise DistutilsModuleError(f"invalid command '{command}'")
860866

861867
@overload
862-
def get_command_obj(
863-
self, command: str, create: Literal[True] = True
864-
) -> 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.")
865870
@overload
866-
def get_command_obj(
867-
self, command: str, create: Literal[False]
868-
) -> Command | None: ...
869-
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:
870873
"""Return the command object for 'command'. Normally this object
871874
is cached on a previous call to 'get_command_obj()'; if no command
872-
object for 'command' is in the cache, then we either create and
873-
return it (if 'create' is true) or return None.
875+
object for 'command' is in the cache, then we create and
876+
return it.
874877
"""
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+
)
875884
cmd_obj = self.command_obj.get(command)
876-
if not cmd_obj and create:
885+
if not cmd_obj:
877886
if DEBUG:
878887
self.announce(
879-
"Distribution.get_command_obj(): "
880-
f"creating '{command}' command object"
888+
f"Distribution.get_command_obj(): creating '{command}' command object"
881889
)
882890

883891
klass = self.get_command_class(command)

0 commit comments

Comments
 (0)