diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-20 13:42:54 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-06-20 13:42:54 +0300 |
commit | 9c080e080a3976083ad9931d1f47400dd33b8833 (patch) | |
tree | d0883b84a85f9c57fce38d19aca69fabf68b75d1 /pylint/pyreverse | |
parent | 992904d43055dd11dd22f43cd30d6265fe2eb2df (diff) | |
download | pylint-9c080e080a3976083ad9931d1f47400dd33b8833.tar.gz |
Improve the readability of a function by using a defaultdict(set) instead of manually checking if a node was already inferred.
Diffstat (limited to 'pylint/pyreverse')
-rw-r--r-- | pylint/pyreverse/inspector.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/pylint/pyreverse/inspector.py b/pylint/pyreverse/inspector.py index 3f31546..c6a3130 100644 --- a/pylint/pyreverse/inspector.py +++ b/pylint/pyreverse/inspector.py @@ -19,7 +19,7 @@ Visitor doing some postprocessing on the astroid tree. Try to resolve definitions (namespace) dictionary, relationship... """ - +import collections import os import astroid @@ -131,7 +131,7 @@ class Linker(IdGeneratorMixIn, utils.LocalsVisitor): specializations.append(node) baseobj.specializations = specializations # resolve instance attributes - node.instance_attrs_type = {} + node.instance_attrs_type = collections.defaultdict(set) for assattrs in node.instance_attrs.values(): for assattr in assattrs: self.handle_assattr_type(assattr, node) @@ -195,14 +195,8 @@ class Linker(IdGeneratorMixIn, utils.LocalsVisitor): handle instance_attrs_type """ try: - values = list(node.infer()) - try: - already_infered = parent.instance_attrs_type[node.attrname] - for valnode in values: - if valnode not in already_infered: - already_infered.append(valnode) - except KeyError: - parent.instance_attrs_type[node.attrname] = values + values = set(node.infer()) + parent.instance_attrs_type[node.attrname].update(values) except astroid.InferenceError: pass |