module documentation

Utilities for checking function overrides used in vm.py.

Class SignatureError Undocumented
Class SignatureErrorType Constants representing various signature mismatch errors.
Function check_overriding_members Check that the method signatures of the new class match base classes.
Constant SIGNATURE_ERROR_TYPE_TO_OPTION_NAME Undocumented
Variable log Undocumented
Function _check_default_values Checks that default parameter values of the overriding method match.
Function _check_keyword_only_parameters Checks that the keyword-only parameters of the overriding method match.
Function _check_positional_parameter_annotations Checks type annotations for positional parameters of the overriding method.
Function _check_positional_parameters Checks that the positional parameters of the overriding method match.
Function _check_return_types Checks that the return types match.
Function _check_signature_compatible Checks if the signatures match for the overridden and overriding methods.
Function _get_parameterized_class_signature_map Returns a map from method names to signatures for a ParameterizedClass.
Function _get_pytd_class_signature_map Returns a map from method names to their signatures for a PyTDClass.
Function _get_varargs_annotation_type Returns the type annotation for the varargs parameter.
Type Alias _SignatureMapType Undocumented
def check_overriding_members(cls, bases, members, matcher, ctx): (source)

Check that the method signatures of the new class match base classes.

SIGNATURE_ERROR_TYPE_TO_OPTION_NAME = (source)

Undocumented

Value
{SignatureErrorType.DEFAULT_PARAMETER_MISMATCH: 'overriding_parameter_count_chec
ks',
 SignatureErrorType.KWONLY_PARAMETER_COUNT_MISMATCH: 'overriding_parameter_count
_checks',
 SignatureErrorType.POSITIONAL_PARAMETER_COUNT_MISMATCH: 'overriding_parameter_c
ount_checks'}

Undocumented

def _check_default_values(method_signature, base_signature): (source)

Checks that default parameter values of the overriding method match. Args: method_signature: signature of the overriding method. base_signature: signature of the overridden method. Returns: SignatureError if a mismatch is detected. Otherwise returns None.

def _check_keyword_only_parameters(method_signature, base_signature, is_subtype): (source)

Checks that the keyword-only parameters of the overriding method match. Args: method_signature: signature of the overriding method. base_signature: signature of the overridden method. is_subtype: a binary function to compare types. Returns: SignatureError if a mismatch is detected. Otherwise returns None.

def _check_positional_parameter_annotations(method_signature, base_signature, is_subtype): (source)

Checks type annotations for positional parameters of the overriding method. Args: method_signature: signature of the overriding method. base_signature: signature of the overridden method. is_subtype: a binary function to compare types. Returns: SignatureError if a mismatch is detected. Otherwise returns None.

def _check_positional_parameters(method_signature, base_signature, is_subtype): (source)

Checks that the positional parameters of the overriding method match. Args: method_signature: signature of the overriding method. base_signature: signature of the overridden method. is_subtype: a binary function to compare types. Returns: SignatureError if a mismatch is detected. Otherwise returns None.

def _check_return_types(method_signature, base_signature, is_subtype): (source)

Checks that the return types match.

def _check_signature_compatible(method_signature, base_signature, stack, matcher, ctx): (source)

Checks if the signatures match for the overridden and overriding methods. Adds the first error found to the context's error log. Two invariants are verified: 1. Every call that is valid for the overridden method is valid for the overriding method. 2. Two calls that are equivalent for the overridden method are equivalent for the overriding method. This translates into the following mapping requirements for overriding method parameters: +----------------------------------------------------------------------------+ | Overridden method | Overriding method | +----------------------------------------------------------------------------+ | Positional-only | Positional-only or | | | positional-or-keyword, any name | +--------------------------------------+-------------------------------------+ | Positional-or-keyword | Positional-or-keyword, same name | +--------------------------------------+-------------------------------------+ | Keyword-only | Positional-or-keyword | | | or keyword-only, same name | +--------------------------------------+-------------------------------------+ | Non-default | Non-default or default | +--------------------------------------+-------------------------------------+ | Default | Default, same default value | +--------------------------------------+-------------------------------------+ | Parameter of type T | Parameter of supertype of T or | | | no annotation | +--------------------------------------+-------------------------------------+ | Parameter without annotation | Parameter with any type annotation | | | or without annotation | +--------------------------------------+-------------------------------------+ | Return type T | Return type - subtype of T or | | | no annotation | +--------------------------------------+-------------------------------------+ | Return type not annotated | Any return type annotation | | | or no annotation | +--------------------------------------+-------------------------------------+ In addition, default parameters of the overriding method don't have to match any parameters of the overridden method. Same name requirement is often violated, so we don't treat is as an error for now and only log a warning. Arguments: method_signature: signature of the overriding method. base_signature: signature of the overridden method. stack: the stack to use for mismatch error reporting. matcher: abstract matcher for type comparison. ctx: pytype abstract context.

def _get_parameterized_class_signature_map(cls: abstract.ParameterizedClass, ctx: _ContextType) -> _SignatureMapType: (source)

Returns a map from method names to signatures for a ParameterizedClass.

def _get_pytd_class_signature_map(cls: abstract.PyTDClass, ctx: _ContextType) -> _SignatureMapType: (source)

Returns a map from method names to their signatures for a PyTDClass.

def _get_varargs_annotation_type(param_type): (source)

Returns the type annotation for the varargs parameter.

_SignatureMapType = (source)

Undocumented

Value
Mapping[str, function.Signature]