stubalyzer package¶
Submodules¶
Module contents¶
- class stubalyzer.ComparisonResult(match_result: MatchResult, symbol: RelevantSymbolNode, reference: Optional[SymbolNode], symbol_name: str, symbol_type: str, reference_name: Optional[str], reference_type: Optional[str], data: Optional[Dict[str, Any]] = None, message_val: Optional[str] = None)[source]¶
Bases:
tuple
Result of comparing two symbol nodes and their types.
- classmethod create(match_result: MatchResult, symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], reference: Optional[mypy.nodes.SymbolNode], data: Optional[Dict[str, Any]] = None, message: Optional[str] = None) ComparisonResult [source]¶
Create a comparison result.
- Parameters
match_result – if the match was successful
symbol – symbol that was checked
reference – reference symbol that was checked against
data – optional additional data
message – optional message
- classmethod create_match(symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], reference: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], data: Optional[Dict[str, Any]] = None, message: Optional[str] = None) ComparisonResult [source]¶
Create a successful comparison result.
- Parameters
symbol – symbol that was checked
reference – reference symbol that was checked against
data – optional additional data
message – optional message
- classmethod create_mislocated_symbol(symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], reference: mypy.nodes.SymbolNode, data: Optional[Dict[str, Any]] = None) ComparisonResult [source]¶
Create an unsuccessful comparison result where the reference symbol was found in a different level of the class hierarchy.
- Parameters
symbol – symbol we wanted to check
reference – symbol that was found somewhere else in the hierarchy
data – optional additional data
- classmethod create_mismatch(symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], reference: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], data: Optional[Dict[str, Any]] = None, message: Optional[str] = None) ComparisonResult [source]¶
Create an unsuccessful comparison result.
- Parameters
symbol – symbol that was checked
reference – reference symbol that was checked against
data – optional additional data
message – optional message
- classmethod create_not_found(symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], data: Optional[Dict[str, Any]] = None) ComparisonResult [source]¶
Create an unsuccessful comparison result where there was no reference symbol found.
- Parameters
symbol – symbol we wanted to check
data – optional additional data
- property data¶
Optional additional data
- property match_result¶
Type of comparison result
- property message: str¶
Human readable result of the comparison
- property message_val¶
Optional message
- property reference¶
Reference symbol that was checked against
- property reference_name¶
Full name of the reference symbol
- property reference_type¶
Type of the reference symbol
- property symbol¶
Symbol that was checked
- property symbol_name¶
Full name of the symbol that was checked
- property symbol_type¶
Type of the symbol that was checked
- class stubalyzer.MatchResult(value)[source]¶
Bases:
Enum
An enumeration.
- MATCH = 'match'¶
- MISLOCATED_SYMBOL = 'mislocated_symbol'¶
- MISMATCH = 'mismatch'¶
- NOT_FOUND = 'not_found'¶
- classmethod declare_mismatch(matchResultString: str) MatchResult [source]¶
- stubalyzer.compare_symbols(symbol: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], reference: Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias]) ComparisonResult [source]¶
Check if the given symbol node is compatible with the reference symbol.
Will return a successful comparison if any of the following holds:
the symbols describe the same class
the symbols are type aliases that resolve to the same type
symbol
is a valid subtype ofreference
(seemypy.subtypes.is_subtype()
)symbol
andreference
somehow overlap (seemypy.meet.is_overlapping_types()
)
- Parameters
symbol – symbol node to validate
reference – symbol node to validate against
- stubalyzer.get_stub_types(stubs_path: str, mypy_conf_path: str, root_path: Optional[str] = None) Iterable[Tuple[Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias], str]] [source]¶
Analyze the stub files in stubs_path and return module and class definitions of stubs as symbol nodes.
Only relevant symbol nodes (e.g. for variables, functions, classes, methods) are returned. They contain the type annotation information.
- Parameters
stubs_path – where all the stub files are located
mypy_conf_path – path to mypy.ini
root_path – path to the code directory where the type analysis is started
- stubalyzer.lookup_symbol(symbol_map: Dict[str, Union[mypy.nodes.Decorator, mypy.nodes.FuncDef, mypy.nodes.OverloadedFuncDef, mypy.nodes.Var, mypy.nodes.TypeInfo, mypy.nodes.TypeVarExpr, mypy.nodes.TypeAlias]], symbol_to_lookup: mypy.nodes.SymbolNode) LookupResult [source]¶
Find the given symbol in the symbol map.
Ideally the symbol is just found under the exact same
fullname
. If not and the symbol is a method, this will take the symbol’s class and look it up in the map and then try to resolve the symbol on that class using its method resolution order.If the result of the lookup has a different
fullname
than the original symbol the given symbol is defined at a different point in the class hierarchy than expected.- Parameters
symbol_map – Dictionary for looking up symbols by their full name
symbol_to_lookup – Symbol to search for
- Returns
The found symbol (if any) and the class it was found on (if any)