Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
code_to_ast can't extract methods in classes #71
Passing a method to
>>> import astor >>> from requests.auth import HTTPDigestAuth >>> node = astor.code_to_ast(HTTPDigestAuth.build_digest_header) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\miau\Documents\repo\astor\astor\file_util.py", line 102, in __call__ return cache[key] KeyError: ('C:\\ProgramData\\Anaconda3\\lib\\site-packages\\requests\\auth.py', 128)
It seems that astor doesn't look into
Yeah, that function's pretty simple right now -- it only works on top-level functions.
Having said that, you can have functions inside classes inside functions inside functions inside classes inside...
Honestly, I don't even remember my use-case for writing that, but I suspect it had to do with testing the code writer.
We'd certainly accept a patch for a more-functional version of this, but I don't have a use-case at the moment.
I wrote a version of the
I make a list of AST nodes,
Then I have a method that descends the AST (note
def _find_funcs(self, parent_ast): for item in parent_ast.body: if type(item) in self.func_types: self.asts[(self.filename, item.lineno)] = item self._find_funcs(item) elif type(item) in self.block_types: self._find_funcs(item)
I haven't tried to port this back to