class documentation

class Signature: (source)

View In Hierarchy

Representation of a Python function signature. Attributes: name: Name of the function. param_names: A tuple of positional parameter names. This DOES include positional-only parameters and does NOT include keyword-only parameters. posonly_count: Number of positional-only parameters. (Python 3.8) varargs_name: Name of the varargs parameter. (The "args" in *args) kwonly_params: Tuple of keyword-only parameters. (Python 3) E.g. ("x", "y") for "def f(a, *, x, y=2)". These do NOT appear in param_names. Ordered like in the source file. kwargs_name: Name of the kwargs parameter. (The "kwargs" in **kwargs) defaults: Dictionary, name to value, for all parameters with default values. annotations: A dictionary of type annotations. (string to type) excluded_types: A set of type names that will be ignored when checking the count of type parameters. type_params: The set of type parameter names that appear in annotations. has_return_annotation: Whether the function has a return annotation. has_param_annotations: Whether the function has parameter annotations. posonly_params: Tuple of positional-only parameters (i.e., the first posonly_count names in param_names).

Class Method from_any Treat `Any` as `f(...) -> Any`.
Class Method from_callable Undocumented
Class Method from_param_names Construct a minimal signature from a name and a list of param names.
Class Method from_pytd Construct an abstract signature from a pytd signature.
Method __init__ Undocumented
Method __repr__ Undocumented
Method add_scope Add scope for type parameters in annotations.
Method check_defaults Raises an error if a non-default param follows a default.
Method check_type_parameter_count Check the count of type parameters in function.
Method del_annotation Undocumented
Method drop_first_parameter Undocumented
Method get_first_arg Returns the first non-self/cls arg, if any.
Method get_self_arg Returns the 'self' or 'cls' arg, if any.
Method has_param Undocumented
Method insert_varargs_and_kwargs Insert varargs and kwargs from args into the signature.
Method iter_args Iterates through the given args, attaching names and expected types.
Method mandatory_param_count Undocumented
Method maximum_param_count Undocumented
Method populate_annotation_dict Populate annotation dict with default values.
Method set_annotation Undocumented
Instance Variable annotations Undocumented
Instance Variable defaults Undocumented
Instance Variable excluded_types Undocumented
Instance Variable kwargs_name Undocumented
Instance Variable kwonly_params Undocumented
Instance Variable name Undocumented
Instance Variable param_names Undocumented
Instance Variable posonly_count Undocumented
Instance Variable type_params Undocumented
Instance Variable varargs_name Undocumented
Property has_param_annotations Undocumented
Property has_return_annotation Undocumented
Property posonly_params Undocumented
Method _postprocess_annotation Postprocess the given annotation.
Method _print_annot Undocumented
Method _print_default Undocumented
Method _replace Returns a copy of the signature with the specified values replaced.
Method _yield_arguments Yield all the function arguments.
Constant _ATTRIBUTES Undocumented
@classmethod
def from_any(cls): (source)

Treat `Any` as `f(...) -> Any`.

@classmethod
def from_callable(cls, val): (source)

Undocumented

@classmethod
def from_param_names(cls, name, param_names, kind=pytd.ParameterKind.REGULAR): (source)

Construct a minimal signature from a name and a list of param names.

@classmethod
def from_pytd(cls, ctx, name, sig): (source)

Construct an abstract signature from a pytd signature.

def __init__(self, name, param_names, posonly_count, varargs_name, kwonly_params, kwargs_name, defaults, annotations, postprocess_annotations=True): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def add_scope(self, module): (source)

Add scope for type parameters in annotations.

def check_defaults(self, ctx): (source)

Raises an error if a non-default param follows a default.

def check_type_parameter_count(self, stack): (source)

Check the count of type parameters in function.

def del_annotation(self, name): (source)

Undocumented

def drop_first_parameter(self): (source)

Undocumented

def get_first_arg(self, callargs): (source)

Returns the first non-self/cls arg, if any.

def get_self_arg(self, callargs): (source)

Returns the 'self' or 'cls' arg, if any.

def has_param(self, name): (source)

Undocumented

def insert_varargs_and_kwargs(self, args): (source)

Insert varargs and kwargs from args into the signature. Args: args: An iterable of passed arg names. Returns: A copy of this signature with the passed varargs and kwargs inserted.

def iter_args(self, args): (source)

Iterates through the given args, attaching names and expected types.

def mandatory_param_count(self): (source)

Undocumented

def maximum_param_count(self): (source)

Undocumented

def populate_annotation_dict(self, annots, ctx, param_names=None): (source)

Populate annotation dict with default values.

def set_annotation(self, name, annotation): (source)

Undocumented

annotations = (source)

Undocumented

defaults = (source)

Undocumented

excluded_types = (source)

Undocumented

kwargs_name = (source)

Undocumented

kwonly_params = (source)

Undocumented

Undocumented

param_names = (source)

Undocumented

posonly_count = (source)

Undocumented

type_params = (source)

Undocumented

varargs_name = (source)

Undocumented

@property
has_param_annotations = (source)

Undocumented

@property
has_return_annotation = (source)

Undocumented

@property
posonly_params = (source)

Undocumented

def _postprocess_annotation(self, name, annotation): (source)

Postprocess the given annotation.

def _print_annot(self, name): (source)

Undocumented

def _print_default(self, name): (source)

Undocumented

def _replace(self, **kwargs): (source)

Returns a copy of the signature with the specified values replaced.

def _yield_arguments(self): (source)

Yield all the function arguments.

_ATTRIBUTES = (source)

Undocumented

Value
set(__init__.__code__.co_varnames[:__init__.__code__.co_argcount])-set(['self',
                                                                        'postpro
cess_annotations'])