class AbstractMatcher(utils.ContextWeakrefMixin): (source)
Matcher for abstract values.
Exception |
|
Undocumented |
Method | __init__ |
Undocumented |
Method | compute |
Compute information about type parameters using one-way unification. |
Method | compute |
Match a Variable against a type. |
Method | match |
Checks a type's MRO for a match for a formal type. |
Method | match |
Match a variable against a type. |
Method | _check |
Undocumented |
Method | _discard |
Undocumented |
Method | _error |
Package up additional error details. |
Method | _get |
Gets the specified attribute from cls, for protocol matching. |
Method | _get |
Get the attributes implemented (or implicit) on a type. |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Helper for matching the parameters of a callable. |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _instantiate |
Instantiate and match an abstract value. |
Method | _is |
Undocumented |
Method | _match |
Checks whether a type is compatible with a protocol. |
Method | _match |
Matches all of var's bindings against other_type. |
Method | _match |
Undocumented |
Method | _match |
Undocumented |
Method | _match |
Used by _match_instance. |
Method | _match |
Undocumented |
Method | _match |
Used by _match_instance. |
Method | _match |
Used by _match_instance_against_type. Matches one MRO entry. |
Method | _match |
Checks whether an instance of a type is compatible with a (formal) type. |
Method | _match |
Used by _match_instance. |
Method | _match |
Match after unwrapping any `Final` annotations. |
Method | _match |
Checks whether left and other_type are compatible in the given attribute. |
Method | _match |
Match a function.Signature against a parameterized callable. |
Method | _match |
Helper function for _match_signature_against_callable. |
Method | _match |
Undocumented |
Method | _match |
See https://www.python.org/dev/peps/pep-0544/#callback-protocols. |
Method | _match |
Checks whether a type is compatible with a (formal) type. |
Method | _match |
Match a TypeVar against another TypeVar. |
Method | _match |
One-way unify value into pytd type given a substitution. |
Method | _merge |
Undocumented |
Method | _merge |
Undocumented |
Method | _mutate |
Undocumented |
Method | _reset |
Undocumented |
Method | _resolve |
Undocumented |
Method | _resolve |
Returns a resolved attribute and whether any unbinding occurred. |
Method | _satisfies |
Enforce that the variable's values share a superclass below object. |
Method | _satisfies |
Enforce a str to NOT be matched against a conflicting iterable type. |
Method | _satisfies |
Enforce that the variable contains only one concrete type. |
Method | _subst |
Undocumented |
Method | _track |
Context manager for handling the protocol cache. |
Instance Variable | _error |
Undocumented |
Instance Variable | _node |
Undocumented |
Instance Variable | _noniterable |
Undocumented |
Instance Variable | _paramspecs |
Undocumented |
Instance Variable | _protocol |
Undocumented |
Instance Variable | _protocol |
Undocumented |
Instance Variable | _recursive |
Undocumented |
Instance Variable | _type |
Undocumented |
Instance Variable | _typed |
Undocumented |
Inherited from ContextWeakrefMixin
:
Class Variable | __slots__ |
Undocumented |
Instance Variable | ctx |
Undocumented |
Property | ctx |
Undocumented |
List[ function.Arg]
, match_all_views: bool
, keep_all_views: bool
= False, alias_map: Optional[ datatypes.UnionFind]
= None) -> List[ GoodMatch]
:
(source)
¶
Compute information about type parameters using one-way unification. Given the arguments of a function call, try to find substitutions that match them against their expected types. Args: args: A sequence of function arguments. match_all_views: If True, every possible match must succeed for the overall match to be considered a success. Otherwise, the overall match succeeds as long as at least one possible match succeeds. keep_all_views: If True, avoid optimizations that discard views. alias_map: Optionally, a datatypes.UnionFind, which stores all the type renaming information, mapping of type parameter name to its representative. Returns: A sequence of GoodMatch results containing the computed substitutions. Raises: MatchError: if any of the arguments does not match its expected type.
MatchResult
:
(source)
¶
Match a Variable against a type. Args: var: A cfg.Variable, containing instances. other_type: An instance of BaseValue. name: Optionally, the variable name. match_all_views: If True, every possible match must succeed for the overall match to be considered a success. Otherwise, the overall match succeeds as long as at least one possible match succeeds. keep_all_views: If True, avoid optimizations that discard views. alias_map: Optionally, a datatypes.UnionFind, which stores all the type renaming information, mapping of type parameter name to its representative. Returns: The match result.
Checks a type's MRO for a match for a formal type. Args: left: The type. other_type: The formal type. allow_compat_builtins: Whether to allow compatible builtins to match - e.g., int against float. Returns: The match, if any, None otherwise.
abstract.BaseValue
, new_value_binding: cfg.Binding
, t: abstract.TypeParameter
, subst: _SubstType
) -> Tuple[ cfg.Variable, bool]
:
(source)
¶
Undocumented
abstract.BaseValue
, name: str
, instance: Optional[ abstract.BaseValue]
, unbind: bool
) -> Tuple[ Optional[ cfg.Variable], bool]
:
(source)
¶
Gets the specified attribute from cls, for protocol matching. Args: cls: The class to get the attribute from. name: The name of the attribute. instance: Optionally, an instance of the class. unbind: Whether to unbind the attribute if it is a bound function. Returns: A tuple of the attribute and whether any unbinding occurred.
Optional[ str]
, expected: abstract.BaseValue
) -> abstract_utils.BadType
:
(source)
¶
Undocumented
Helper for matching the parameters of a callable. Args: callable_type: The callable being matched against. Returns: A special param matcher: (left, right, subst) -> Optional[subst]. left: An argument to be matched against a parameter of callable_type. right: A parameter of callable_type. subst: The current substitution dictionary. If the matcher returns a non-None subst dict, then the match has succeeded via special matching rules for single TypeVars. Otherwise, the caller should next attempt normal matching on the inputs. (See _match_signature_against_callable for a usage example.)
Checks whether a type is compatible with a protocol. Args: left: An instance of a type. other_type: A protocol. subst: The current type parameter assignment. view: The current mapping of Variable to Value. Returns: A new type parameter assignment if the matching succeeded, None otherwise.
abstract.BaseValue
, other_type: typed_dict.TypedDictClass
) -> bool
:
(source)
¶
Undocumented
Used by _match_instance_against_type. Matches one MRO entry. Called after the instance has been successfully matched against a formal type to do any remaining matching special to the type. Args: left: The instance type, which may be different from instance.cls depending on where in the mro the match happened. instance: The instance. other_type: The formal type that was successfully matched against. subst: The current type parameter assignment. view: The current mapping of Variable to Value. Returns: A new type parameter assignment if the matching succeeded, None otherwise.
Checks whether an instance of a type is compatible with a (formal) type. Args: left: An instance of a type. other_type: A formal type. E.g. abstract.Class or abstract.Union. subst: The current type parameter assignment. view: The current mapping of Variable to Value. Returns: A new type parameter assignment if the matching succeeded, None otherwise.
abstract.BaseValue
, value: cfg.Binding
, other_type: abstract.BaseValue
, subst: _SubstType
, view: _ViewType
) -> Optional[ _SubstType]
:
(source)
¶
Match after unwrapping any `Final` annotations.
Checks whether left and other_type are compatible in the given attribute. Args: left: An instance of a type. other_type: A protocol. attribute: An attribute name. subst: The current type parameter assignment. view: The current mapping of Variable to Value. Returns: A new type parameter assignment if the matching succeeded, None otherwise.
Helper function for _match_signature_against_callable.
Checks whether a type is compatible with a (formal) type. Args: left: A type. other_type: A formal type. E.g. abstract.Class or abstract.Union. subst: The current type parameter assignment. view: The current mapping of Variable to Value. Returns: A new type parameter assignment if the matching succeeded, None otherwise.
cfg.Binding
, other_type: abstract.BaseValue
, subst: _SubstType
, view: _ViewType
) -> Optional[ _SubstType]
:
(source)
¶
One-way unify value into pytd type given a substitution. Args: value: A cfg.Binding. other_type: A BaseValue instance. subst: The current substitution. This dictionary is not modified. view: A mapping of Variable to Value. Returns: A new (or unmodified original) substitution dict if the matching succeeded, None otherwise.
str
, formal: abstract.BaseValue
, old_matches: Optional[ List[ GoodMatch]]
, new_matches: List[ GoodMatch]
, keep_all_views: bool
, has_self: bool
) -> List[ GoodMatch]
:
(source)
¶
Undocumented
abstract.BaseValue
, unbind: bool
) -> abstract.BaseValue
:
(source)
¶
Undocumented
cfg.Variable
, unbind: bool
) -> Tuple[ cfg.Variable, bool]
:
(source)
¶
Returns a resolved attribute and whether any unbinding occurred.
Context manager for handling the protocol cache. Some protocols have methods that return instances of the protocol, e.g. Iterator.next returns Iterator. This will cause an infinite loop, which can be avoided by tracking partially matched protocols. To prevent collisions, keys are removed from the cache as soon as match is completed. Yields: Into the protocol matching context.