Merge lp:~pyflakes-dev/pyflakes/1107587-add-builtins into lp:pyflakes

Proposed by Florent
Status: Merged
Merged at revision: 63
Proposed branch: lp:~pyflakes-dev/pyflakes/1107587-add-builtins
Merge into: lp:pyflakes
Diff against target: 42 lines (+6/-2)
2 files modified
NEWS.txt (+1/-0)
pyflakes/checker.py (+5/-2)
To merge this branch: bzr merge lp:~pyflakes-dev/pyflakes/1107587-add-builtins
Reviewer Review Type Date Requested Status
Pyflakes Dev Pending
Review via email: mp+145125@code.launchpad.net

Description of the change

Add flexibility for the magic built-ins.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS.txt'
2--- NEWS.txt 2013-01-27 15:09:36 +0000
3+++ NEWS.txt 2013-01-28 07:35:32 +0000
4@@ -6,6 +6,7 @@
5 - Allow function redefinition for modern property construction via
6 property.setter/deleter.
7 - Do not report undefined name in __all__ if import * is used.
8+ - Support specifying additional built-ins in `Checker` constructor.
9 - Handle problems with the encoding of source files.
10 - Remove dependency on Twisted for the tests.
11 - Support `python setup.py test` and `python setup.py develop`.
12
13=== modified file 'pyflakes/checker.py'
14--- pyflakes/checker.py 2013-01-27 15:04:53 +0000
15+++ pyflakes/checker.py 2013-01-28 07:35:32 +0000
16@@ -187,13 +187,16 @@
17
18 nodeDepth = 0
19 traceTree = False
20+ builtIns = set(dir(builtins)) | set(_MAGIC_GLOBALS)
21
22- def __init__(self, tree, filename='(none)'):
23+ def __init__(self, tree, filename='(none)', builtins=None):
24 self._deferredFunctions = []
25 self._deferredAssignments = []
26 self.deadScopes = []
27 self.messages = []
28 self.filename = filename
29+ if builtins:
30+ self.builtIns = self.builtIns.union(builtins)
31 self.scopeStack = [ModuleScope()]
32 self.futuresAllowed = True
33 self.handleChildren(tree)
34@@ -351,7 +354,7 @@
35 try:
36 self.scopeStack[0][name].used = (self.scope, node.lineno)
37 except KeyError:
38- if ((not hasattr(builtins, name)) and name not in _MAGIC_GLOBALS and not importStarred):
39+ if not importStarred and name not in self.builtIns:
40 if (os.path.basename(self.filename) == '__init__.py' and name == '__path__'):
41 # the special name __path__ is valid only in packages
42 pass

Subscribers

People subscribed via source and target branches

to all changes: