8000 bpo-39411: pyclbr rewrite on AST by isidentical · Pull Request #18103 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39411: pyclbr rewrite on AST #18103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 11, 2020
Merged
Prev Previous commit
Next Next commit
Revert support for method aliases
  • Loading branch information
isidentical committed Nov 10, 2020
commit dbf563ad368ba383d5b5d7a158c9146819b538d6
26 changes: 0 additions & 26 deletions Lib/pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,32 +207,6 @@ def visit_ClassDef(self, node):
self.generic_visit(node)
self.stack.pop()

def visit_Assign(self, node):
if not self.single_target_function_assign(node):
return

name = node.targets[0].id
value = self.tree[node.value.id]
parent = self.stack[-1]
child = Function(
value.module, name, value.file, node.lineno, parent, value.is_async
)
child.children = copy.deepcopy(value.children)
parent.children[name] = child
parent.methods[name] = node.lineno

def single_target_function_assign(self, node):
"""Check if given assignment consists from a single target
and single value within a class namespace. Check value for if it
is an already defined function."""

return (len(node.targets) == 1
and len(self.stack) > 0
and isinstance(self.stack[-1], Class)
and isinstance(node.targets[0], ast.Name)
and isinstance(node.value, ast.Name)
and isinstance(self.tree.get(node.value.id), Function))

def visit_FunctionDef(self, node, *, is_async=True):
parent = self.stack[-1] if self.stack else None
function = Function(
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/pyclbr_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class C (B):

d = 10

f = f
# XXX: This causes test_pyclbr.py to fail, but only because the
# introspection-based is_method() code in the test can't
# distinguish between this and a genuine method function like m().
# The pyclbr.py module gets this right as it parses the text.
#
#f = f
< 45C6 /td>
def m(self): pass

Expand Down
0