MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

_ParameterKindClass · 0.85
isinstanceFunction · 0.85
formatMethod · 0.45
isdigitMethod · 0.45
isidentifierMethod · 0.45

Tested by

no test coverage detected