Move the construction of generated_members into open.

authorClaudiu Popa <pcmanticore@gmail.com>
changeset70703f84d72b
branchdefault
phasepublic
hiddenno
parent revision#ab53ce04b60e Don't emit super-on-old-class on classes with unknown bases.
child revision#9a545cc2e2b6 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 70703f84d72b6097b6381e520a797a4fa39db566
# Parent ab53ce04b60ec8fc0ab61734c78f897f27fc3445
Move the construction of generated_members into open.

diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
@@ -304,11 +304,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 
@@ -322,23 +330,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