diff options
| author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-09-15 15:55:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-15 15:55:50 +0200 |
| commit | 47529c4ff478354a2468a85e9fa43db39b93c574 (patch) | |
| tree | 7f4bfd5d6a6cbf20973e6d2609fdbda4e8a4848a | |
| parent | 8d99991c8ca1a4b3647d1eb91ea9bd3e3873d977 (diff) | |
| download | astroid-git-47529c4ff478354a2468a85e9fa43db39b93c574.tar.gz | |
Add Arguments typing to Lambda + FunctionDef (#1174)
| -rw-r--r-- | astroid/nodes/scoped_nodes.py | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py index 38d234d2..f9b4a6ed 100644 --- a/astroid/nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes.py @@ -69,7 +69,7 @@ from astroid.exceptions import ( from astroid.interpreter.dunder_lookup import lookup from astroid.interpreter.objectmodel import ClassModel, FunctionModel, ModuleModel from astroid.manager import AstroidManager -from astroid.nodes import Const, node_classes +from astroid.nodes import Arguments, Const, node_classes ITER_METHODS = ("__iter__", "__getitem__") EXCEPTION_BASE_CLASSES = frozenset({"Exception", "BaseException"}) @@ -1190,7 +1190,6 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): :returns: 'method' if this is a method, 'function' otherwise. :rtype: str """ - # pylint: disable=no-member if self.args.arguments and self.args.arguments[0].name == "self": if isinstance(self.parent.scope(), ClassDef): return "method" @@ -1214,11 +1213,8 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): :type: dict(str, NodeNG) """ - self.args = [] - """The arguments that the function takes. - - :type: Arguments or list - """ + self.args: Arguments + """The arguments that the function takes.""" self.body = [] """The contents of the function body. @@ -1228,11 +1224,10 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): super().__init__(lineno, col_offset, parent) - def postinit(self, args, body): + def postinit(self, args: Arguments, body): """Do some setup after initialisation. :param args: The arguments that the function takes. - :type args: Arguments :param body: The contents of the function body. :type body: list(NodeNG) @@ -1276,10 +1271,6 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): :returns: The names of the arguments. :rtype: list(str) """ - # pylint: disable=no-member; github.com/pycqa/astroid/issues/291 - # args is in fact redefined later on by postinit. Can't be changed - # to None due to a strong interaction between Lambda and FunctionDef. - if self.args.arguments: # maybe None with builtin functions names = _rec_get_names(self.args.arguments) else: @@ -1319,10 +1310,6 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): globals or builtin). :rtype: tuple(str, list(NodeNG)) """ - # pylint: disable=no-member; github.com/pycqa/astroid/issues/291 - # args is in fact redefined later on by postinit. Can't be changed - # to None due to a strong interaction between Lambda and FunctionDef. - if node in self.args.defaults or node in self.args.kw_defaults: frame = self.parent.frame() # line offset to avoid that def func(f=func) resolve the default @@ -1440,7 +1427,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): # pylint: disable=arguments-differ; different than Lambdas def postinit( self, - args, + args: Arguments, body, decorators=None, returns=None, @@ -1450,7 +1437,6 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): """Do some setup after initialisation. :param args: The arguments that the function takes. - :type args: Arguments or list :param body: The contents of the function body. :type body: list(NodeNG) |
