0

What is the meaning of a lone star '*' in the parameter list of a Python function?

I found it in the source of scikit-learn and haven't seen it before. I'm familiar with the concepts of positional and keyword arguments (*args, **vargs). I'm assuming, here it has something to do with the _deprecate_positional_args decorator, but the syntax of a lone star as a function parameter seems to be allowed in pure Python 3.7 even without the decorator.

My guess is, it makes it impossible to specify any keyword arguments after the star as positional arguments (as would actually make sense for a parameter called 'safe').

# Part of https://github.com/scikit-learn/scikit-learn.git
# commit 7117a6313791db6f8b737bac28c1f47277a68cfb
# Quoting from sklearn/base.py:
# ...
from .utils.validation import _deprecate_positional_args
# ...

@_deprecate_positional_args
def clone(estimator, *, safe=True):
    """Constructs a new estimator with the same parameters.
    (rest omitted)
    """
# ...
Adomas Baliuka
  • 673
  • 1
  • 7
  • 25

1 Answers1

1

My guess is, it makes it impossible to specify any keyword arguments after the star as positional arguments (as would actually make sense for a parameter called 'safe').

You are right, arguments following lone * are dubbed keyword-only arguments, this feature is defined by PEP 3102.

Daweo
  • 10,139
  • 2
  • 5
  • 10