Module implementing a node visitor for function type annotations.
AST_ARG_TYPES |
Argument | Class representing a function argument. |
Function | Class representing a function. |
FunctionVisitor | Class implementing a node visitor to check function annotations. |
ReturnVisitor | Class implementing a node visitor to check the return statements of a function node. |
None |
Class representing a function argument.
None |
fromNode | Class method to create an Argument object based on the given node. |
Argument | Constructor |
_isAnnotatedAny | Static method to check if the provided expression node is annotated with 'typing.Any'. |
Class method to create an Argument object based on the given node.
Constructor
Static method to check if the provided expression node is annotated with 'typing.Any'.
Support is provided for the following patterns:
* 'from typing import Any; foo: Any'
* 'import typing; foo: typing.Any'
* 'import typing as
Class representing a function.
None |
fromNode | Class method to create a Function object from ast.FunctionDef or ast.AsyncFunctionDef nodes. |
Function | Constructor |
__decoratorChecker | Private method to check the provided decorator for a match against the provided set of check names. |
getAnnotatedArguments | Public method to get list of arguments with type annotations. |
getMissedAnnotations | Public method to provide a list of arguments with missing type annotations. |
hasDecorator | Public method to check whether the function node is decorated by any of the provided decorators. |
isDynamicallyTyped | Public method to check, if a function definition is dynamically typed (i.e. |
isFullyAnnotated | Public method to check, if the function definition is fully type annotated. |
_singleLineColonSeeker | Static method to find the line & column indices of a single line function definition. |
colonSeeker | Static method to find the line & column indices of the function definition's closing colon. |
getClassDecoratorType | Static method to get the class method's decorator type from its function node. |
getFunctionType | Static method to determine the function's FunctionType from its name. |
Class method to create a Function object from ast.FunctionDef or ast.AsyncFunctionDef nodes.
Accept the source code, as a list of strings, in order to get the column where the function definition ends.
With exceptions, input kwargs are passed straight through to Function's __init__. The following kwargs will be overridden: * function_type * class_decorator_type * args
Constructor
Private method to check the provided decorator for a match against the provided set of check names.
Decorators are assumed to be of the following form: * `a.name` or `a.name()` * `name` or `name()`
Note: Deeper imports (e.g. `a.b.name`) are not explicitly supported.
Public method to get list of arguments with type annotations.
Public method to provide a list of arguments with missing type annotations.
Public method to check whether the function node is decorated by any of the provided decorators.
Decorator matching is done against the provided `checkDecorators` set. Decorators are assumed to be either a module attribute (e.g. `@typing.overload`) or name (e.g. `@overload`). For the case of a module attribute, only the attribute is checked against `overload_decorators`.
Note: Deeper decorator imports (e.g. `a.b.overload`) are not explicitly supported.
Public method to check, if a function definition is dynamically typed (i.e. completely lacking hints).
Public method to check, if the function definition is fully type annotated.
Note: self.args will always include an Argument object for return.
Static method to find the line & column indices of a single line function definition.
Static method to find the line & column indices of the function definition's closing colon.
Static method to get the class method's decorator type from its function node.
Only @classmethod and @staticmethod decorators are identified; all other decorators are ignored
If @classmethod or @staticmethod decorators are not present, this function will return None.
Static method to determine the function's FunctionType from its name.
MethodType is determined by the following priority: 1. Special: function name prefixed & suffixed by "__" 2. Private: function name prefixed by "__" 3. Protected: function name prefixed by "_" 4. Public: everything else
Class implementing a node visitor to check function annotations.
AstFuncTypes |
visit_AsyncFunctionDef |
visit_ClassDef |
visit_FunctionDef |
None |
FunctionVisitor | Constructor |
switchContext | Public method implementing a context switcher as a generic function visitor in order to track function context. |
None |
Constructor
Public method implementing a context switcher as a generic function visitor in order to track function context.
Without keeping track of context, it's challenging to reliably differentiate class methods from "regular" functions, especially in the case of nested classes.
Class implementing a node visitor to check the return statements of a function node.
If the function node being visited has an explicit return statement of anything other than `None`, the `instance.hasOnlyNoneReturns` flag will be set to `False`.
If the function node being visited has no return statement, or contains only return statement(s) that explicitly return `None`, the `instance.hasOnlyNoneReturns` flag will be set to `True`.
Due to the generic visiting being done, we need to keep track of the context in which a non-`None` return node is found. These functions are added to a set that is checked to see whether nor not the parent node is present.
visit_AsyncFunctionDef |
visit_FunctionDef |
None |
ReturnVisitor | Constructor |
hasOnlyNoneReturns | Public method indicating, that the parent node isn't in the visited nodes that don't return `None`. |
switchContext | Public method implementing a context switcher as a generic function visitor in order to track function context. |
visit_Return | Public method to check each Return node to see if it returns anything other than `None`. |
None |
Constructor
Public method indicating, that the parent node isn't in the visited nodes that don't return `None`.
Public method implementing a context switcher as a generic function visitor in order to track function context.
Without keeping track of context, it's challenging to reliably differentiate class methods from "regular" functions, especially in the case of nested classes.
Public method to check each Return node to see if it returns anything other than `None`.
If the node being visited returns anything other than `None`, its parent context is added to the set of non-returning child nodes of the parent node.