diff options
author | Alphadelta14 <alpha@alphaservcomputing.solutions> | 2021-08-01 15:05:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-01 21:05:25 +0200 |
commit | ac95965bf32b4b4094bacedb422ba5de515bb85c (patch) | |
tree | 49136184e8d2d5abde6075c58ed95506dfa422b9 /astroid/objects.py | |
parent | e17862654fc0585e63f5ab6785eab23787e91e9b (diff) | |
download | astroid-git-ac95965bf32b4b4094bacedb422ba5de515bb85c.tar.gz |
Fix incorrect scope for functools partials (#1097)
* Use scope parent
* Do not set name onto parent frame for partials
* Add test case that captures broken scopes
Diffstat (limited to 'astroid/objects.py')
-rw-r--r-- | astroid/objects.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/astroid/objects.py b/astroid/objects.py index 1a32b52d..a598c5bb 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -260,7 +260,10 @@ class PartialFunction(scoped_nodes.FunctionDef): def __init__( self, call, name=None, doc=None, lineno=None, col_offset=None, parent=None ): - super().__init__(name, doc, lineno, col_offset, parent) + super().__init__(name, doc, lineno, col_offset, parent=None) + # A typical FunctionDef automatically adds its name to the parent scope, + # but a partial should not, so defer setting parent until after init + self.parent = parent self.filled_positionals = len(call.positional_arguments[1:]) self.filled_args = call.positional_arguments[1:] self.filled_keywords = call.keyword_arguments |