bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
7143.1.1
by Jelmer Vernooij
Add simple pyflakes hack that adds support for lazy imports. |
1 |
#!/usr/bin/python3
|
2 |
||
3 |
from __future__ import absolute_import |
|
4 |
||
5 |
import ast |
|
6 |
||
7 |
from pyflakes.checker import Checker, ImportationFrom |
|
8 |
||
9 |
# Do some monkey patching..
|
|
10 |
def CALL(self, node): |
|
11 |
if isinstance(node.func, ast.Name) and node.func.id == 'lazy_import': |
|
12 |
self.LAZY_IMPORT(node) |
|
13 |
elif (isinstance(node.func, ast.Attribute) and |
|
14 |
node.func.attr == 'lazy_import' and |
|
15 |
node.func.value.id == 'lazy_import'): |
|
16 |
self.LAZY_IMPORT(node) |
|
17 |
return self.handleChildren(node) |
|
18 |
||
19 |
Checker.CALL = CALL |
|
20 |
||
21 |
def LAZY_IMPORT(self, node): |
|
22 |
from breezy.lazy_import import ImportProcessor |
|
23 |
processor = ImportProcessor() |
|
|
7143.1.3
by Jelmer Vernooij
Skip non-str second argument to lazy_import. |
24 |
if not isinstance(node.args[1], ast.Str): |
25 |
# Not sure how to deal with this..
|
|
26 |
return
|
|
|
7143.1.1
by Jelmer Vernooij
Add simple pyflakes hack that adds support for lazy imports. |
27 |
import_text = node.args[1].s |
28 |
scope = {} |
|
29 |
processor.lazy_import(scope, import_text) |
|
30 |
for name, (path, sub, scope) in processor.imports.items(): |
|
31 |
importation = ImportationFrom(name, node, '.'.join(path), scope) |
|
32 |
self.addBinding(node, importation) |
|
33 |
||
34 |
Checker.LAZY_IMPORT = LAZY_IMPORT |
|
35 |
||
36 |
||
37 |
if __name__ == '__main__': |
|
38 |
from pyflakes import __main__ |
|
39 |
__main__.main() |