Move the construction of generated_members into open.

authorClaudiu Popa <pcmanticore@gmail.com>
changeset83afd8d7a075
branchdefault
phasepublic
hiddenno
parent revision#4e5a1be18df2 Added a new error, 'relative-beyond-top-level'.
child revision#083425ea56b0 Allow statements in if or try blocks containing imports.
files modified by this revision
pylint/checkers/typecheck.py
# HG changeset patch
# User Claudiu Popa <pcmanticore@gmail.com>
# Date 1449488472 -7200
# Mon Dec 07 13:41:12 2015 +0200
# Node ID 83afd8d7a075ef7efb3930e79b4ffd645dae803f
# Parent 4e5a1be18df2799d29847ed51dd4b86c2903c2ea
Move the construction of generated_members into open.

diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
@@ -315,11 +315,19 @@
1                 ),
2                )
3 
4      def open(self):
5          # do this in open since config not fully initialized in __init__
6 -        self.generated_members = list(self.config.generated_members)
7 +        # generated_members may contain regular expressions
8 +        # (surrounded by quote `"` and followed by a comma `,`)
9 +        # REQUEST,aq_parent,"[a-zA-Z]+_set{1,2}"' =>
10 +        # ('REQUEST', 'aq_parent', '[a-zA-Z]+_set{1,2}')
11 +        if isinstance(self.config.generated_members, str):
12 +            gen = shlex.shlex(self.config.generated_members)
13 +            gen.whitespace += ','
14 +            gen.wordchars += '[]-+'
15 +            self.config.generated_members = tuple(tok.strip('"') for tok in gen)
16 
17      def visit_assignattr(self, node):
18          if isinstance(node.assign_type(), astroid.AugAssign):
19              self.visit_attribute(node)
20 
@@ -333,23 +341,15 @@
21          to avoid too much false positives for now, we'll consider the code as
22          correct if a single of the inferred nodes has the accessed attribute.
23 
24          function/method, super call and metaclasses are ignored
25          """
26 -        # generated_members may contain regular expressions
27 -        # (surrounded by quote `"` and followed by a comma `,`)
28 -        # REQUEST,aq_parent,"[a-zA-Z]+_set{1,2}"' =>
29 -        # ('REQUEST', 'aq_parent', '[a-zA-Z]+_set{1,2}')
30 -        if isinstance(self.config.generated_members, str):
31 -            gen = shlex.shlex(self.config.generated_members)
32 -            gen.whitespace += ','
33 -            gen.wordchars += '[]-+'
34 -            self.config.generated_members = tuple(tok.strip('"') for tok in gen)
35          for pattern in self.config.generated_members:
36              # attribute is marked as generated, stop here
37              if re.match(pattern, node.attrname):
38                  return
39 +
40          try:
41              infered = list(node.expr.infer())
42          except exceptions.InferenceError:
43              return
44          # list of (node, nodename) which are missing the attribute