Skip to content

Commit

Permalink
Remove handle_py3_kw_only_args
Browse files Browse the repository at this point in the history
- Drop handle_py3_kw_only_args() which is no longer needed, and was mislabeled.
  The root issue was my confusion between keyword-only arguments (*) and
  position-only arguments (/), the first being added in early 3.x and the later
  being a 3.8+ feature.  So the feature I wanted was already there, nice!
  • Loading branch information
lowell80 committed Sep 20, 2023
1 parent 31817f4 commit f1871d9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
5 changes: 1 addition & 4 deletions ksconf/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from subprocess import Popen
from typing import Callable, List, TextIO

from ksconf.compat import handle_py3_kw_only_args
from ksconf.consts import EXIT_CODE_INTERNAL_ERROR, is_debug

QUIET = -1
Expand Down Expand Up @@ -76,8 +75,7 @@ def _log(self, message, verbosity=0):
self._output.write(message)
self._output.write("\n")

def run(self, executable, *args, **kw_only):
# PY38 signature: run(self, executable, /, *args, cwd=None)
def run(self, executable, *args, cwd=None):
""" Execute an OS-level command regarding the build process.
The process will run withing the working directory of the build folder.
Expand All @@ -86,7 +84,6 @@ def run(self, executable, *args, **kw_only):
:param str cwd: Optional kw arg to change the working directory. This
defaults to the build folder.
"""
(cwd,) = handle_py3_kw_only_args(kw_only, ("cwd", None))
# XXX: Update the external pip call to detach stdout / stderr if self.is_quiet
args = [executable] + [str(s) for s in args]
cwd = cwd or str(self.build_path)
Expand Down
43 changes: 0 additions & 43 deletions ksconf/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,6 @@
from functools import lru_cache
cache = lru_cache(maxsize=None)


def handle_py3_kw_only_args(kw, *default_args):
""" Fake support for Python 3.8+ style keyword-only style arguments, or ``*`` arg syntax.
Example Python 3.8+ syntax:
.. code-block:: py
def f(arg, *args, a=True, b=False):
...
Example Python 3.7 (and earlier) syntax with this helper function:
.. code-block:: py
def f(arg, *args, **kw_only):
a, b = handle_py3_kw_only_args(kw_only, ("a", True), ("b", False))
...
:param dict kw: keyword arguments provided to the calling function. Be aware
that this dict will be empty after this function is done.
:param tuple default_args: pairs of keyword argument to the caller function
in argument (arg_name, default_value) order.
:raises TypeError: if ``kw`` contains any keys not defined in ``args``
This mirrors Python's native behavior when an unexpected
argument is passed to a function.
"""
out = []
for arg_name, arg_default in default_args:
try:
out.append(kw.pop(arg_name))
except KeyError:
out.append(arg_default)
if kw:
import inspect
caller = inspect.currentframe().f_back.f_code.co_name
# Should all unexpected args be reported? feels like this good enough
raise TypeError("{} got an unexpected keyword argument '{}'"
.format(caller, list(kw)[0]))
return out


del sys

__all__ = [
Expand All @@ -88,5 +46,4 @@ def f(arg, *args, **kw_only):
"Set",
"Tuple",
"cache",
"handle_py3_kw_only_args",
]

0 comments on commit f1871d9

Please sign in to comment.