This is an announcement to make you consider using Jedi as a static
analysis library for your own stuff. If you want to build a
refactoring or a linter library for Python you should just be using
Jedi, it's doing all the work for you.
I have recently released Jedi 0.9.0. This release marks a change in
the way how Jedi is structured. In the past Jedi had one objective
Now Jedi is a general purpose, high quality static analysis engine.
The static analysis capabilities are really good, but it's hard to
describe what it does exactly. It's better than any other static
analysis engine out there for sure.
Jedi's parser is built on the lib2to3 and therefore is able to create
a "round-trip" representation of source code. After parsing and
modifications to the syntax tree, Jedi echos the exact same source
tree with the changes included, which is neat for refactoring.
The parser also has built-in error recovery as well as support for
different Python versions (Python version is a param).
Jedi has become quite powerful. If you're considering Jedi, I'm very
happy to get you started. Let's talk!
I am currently using the Python ast package with ast.NodeVisitor to
generate code for another VM. I found Astroid during my search for a
type inference solution.
The documentation is abit sparse for me, and I was hoping someone
could help me with extending the AST with Astroid's.
At first I tried AstroidManager().ast_from_file(f)
but I got astroid.exceptions.AstroidBuildingException: Unable to load
module tests/single_function.se (No module named
I then tried something like
ast_se = ast.parse(code)
module_se = TreeRebuilder(AstroidManager()).visit_module(ast_se,
"blah", "blah", "blah")
Which gets me a module, but I couldn't seem to pass it to
or ast.dump(module_se) (not surprising as it's not an AST)
So my question is, how do I build an AST with Astroid from a
stand-alone file, walk the ast in a fashion similar to NodeVisitor,
and if possible query types from the extended AST nodes?
Inside Google we use pylint in many ways. In some we have plenty
context for imports, etc. In others we have only on file in isolation and
need to lint it the best we can without any context for imports, etc. To
support that we have a pylint mode where it should ignore everything
but the file given to it.
This has been kind of working for a long time, but some bugs were
filed where we noticed our pylint was in fact behaving differently for
files with context available and those without. I eventually traced the
issue to the fact that when astroid sees a star import (from foo import *)
it will try to load symbols for the import. When the import makes sense
(in one example, the file is in a directory where it may work) it succeeds
in importing symbols; when the import makes no sense (in another example,
the file is isolated somewhere python won't find any symbol to import)
then it will not add the symbols.
The specific place this happens is in astroid/builder.py:
def add_from_names_to_locals(self, node):
"""store imported names to the locals;
resort the locals if coming from a delayed node
_key_func = lambda node: node.fromlineno
for (name, asname) in node.names:
if name == '*':
imported = node.do_import_module()
for name in imported.wildcard_import_names():
node.parent.set_local(asname or name, node)
sort_locals(node.parent.scope().locals[asname or name])
My questions is: Is there a (non-hacky) way of telling astroid/pylint
that I really *really* don't want them to consider anything else from
context and actually use only the file I provided? If not, is it reasonable
to add an option for that? (I can do the coding, but not before discussing
Thank you very much,
*Daniel Balparda de Carvalho* 梅巴達 <balparda(a)google.com>
Python Team, Google US-MTV-CL2 3K5B, +1-650-933-8587
It seems like when I have a function that does "del" on a global variable,
flake complains that a local variable is referenced before assignment. As
far as I know, the following is valid code:
server = None
server = None
test.py:6:8: F823 local variable 'server' (defined in enclosing scope on
line 1) referenced before assignment
I'm using flake --version: 2.1.0 (pep8: 1.4.6, mccabe: 0.2.1, pyflakes:
I understand that the "del" statement is redundant, but I don't think that
it is wrong, per se. Is this code actually incorrect? If not, is there a
way to suppress this error message? I'm interested in figuring this out as
part of an effort to convince a coworker to start using flake on his/her