Skip to content

Commit

Permalink
Add Arguments typing to Lambda + FunctionDef (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Sep 15, 2021
1 parent 8d99991 commit 47529c4
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions astroid/nodes/scoped_nodes.py
Expand Up @@ -69,7 +69,7 @@
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"})
Expand Down Expand Up @@ -1190,7 +1190,6 @@ def type(self):
: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"
Expand All @@ -1214,11 +1213,8 @@ def __init__(self, lineno=None, col_offset=None, parent=None):
: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.
Expand All @@ -1228,11 +1224,10 @@ def __init__(self, lineno=None, col_offset=None, parent=None):

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)
Expand Down Expand Up @@ -1276,10 +1271,6 @@ def argnames(self):
: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:
Expand Down Expand Up @@ -1319,10 +1310,6 @@ def scope_lookup(self, node, name, offset=0):
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
Expand Down Expand Up @@ -1440,7 +1427,7 @@ def __init__(self, name=None, doc=None, lineno=None, col_offset=None, parent=Non
# pylint: disable=arguments-differ; different than Lambdas
def postinit(
self,
args,
args: Arguments,
body,
decorators=None,
returns=None,
Expand All @@ -1450,7 +1437,6 @@ def postinit(
"""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)
Expand Down

0 comments on commit 47529c4

Please sign in to comment.