MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/inspect.py:2687–2728  ·  view source on GitHub ↗
(self, name, kind, *, default=_empty, annotation=_empty)

Source from the content-addressed store, hash-verified

2685 empty = _empty
2686
2687 def __init__(self, name, kind, *, default=_empty, annotation=_empty):
2688 try:
2689 self._kind = _ParameterKind(kind)
2690 except ValueError:
2691 raise ValueError(f'value {kind!r} is not a valid Parameter.kind')
2692 if default is not _empty:
2693 if self._kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
2694 msg = '{} parameters cannot have default values'
2695 msg = msg.format(self._kind.description)
2696 raise ValueError(msg)
2697 self._default = default
2698 self._annotation = annotation
2699
2700 if name is _empty:
2701 raise ValueError('name is a required attribute for Parameter')
2702
2703 if not isinstance(name, str):
2704 msg = 'name must be a str, not a {}'.format(type(name).__name__)
2705 raise TypeError(msg)
2706
2707 if name[0] == '.' and name[1:].isdigit():
2708 # These are implicit arguments generated by comprehensions. In
2709 # order to provide a friendlier interface to users, we recast
2710 # their name as "implicitN" and treat them as positional-only.
2711 # See issue 19611.
2712 if self._kind != _POSITIONAL_OR_KEYWORD:
2713 msg = (
2714 'implicit arguments must be passed as '
2715 'positional or keyword arguments, not {}'
2716 )
2717 msg = msg.format(self._kind.description)
2718 raise ValueError(msg)
2719 self._kind = _POSITIONAL_ONLY
2720 name = 'implicit{}'.format(name[1:])
2721
2722 # It's possible for C functions to have a positional-only parameter
2723 # where the name is a keyword, so for compatibility we'll allow it.
2724 is_keyword = iskeyword(name) and self._kind is not _POSITIONAL_ONLY
2725 if is_keyword or not name.isidentifier():
2726 raise ValueError('{!r} is not a valid parameter name'.format(name))
2727
2728 self._name = name
2729
2730 def __reduce__(self):
2731 return (type(self),

Callers

nothing calls this directly

Calls 4

_ParameterKindClass · 0.85
isdigitMethod · 0.80
isidentifierMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected