summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-03-06 13:21:12 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2020-03-06 13:22:41 +0100
commit7120d894635662d49b05c0cc5d664b5a25544605 (patch)
tree1176b2a0febe1a796d2254013456d24442166327 /tests
parent17a5ee681bcf4aacffcc4ec5afbc3436cfdc4537 (diff)
downloadastroid-git-7120d894635662d49b05c0cc5d664b5a25544605.tar.gz
Raise ``AttributeInferenceError`` when ``getattr()`` receives an empty name
If `Module.getattr` received an empty string (as a result of inference for example), `astroid` would have returned the same Module again, which leads to false positives in pylint, since the expected output was of a different type. Rather than allowing empty names to pass through `getattr()`, we simply raise an error earlier. Close PyCQA/pylint#2991
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_inference.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index 49ff6cdc..7f86de4d 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -5729,5 +5729,19 @@ def test_inferring_properties_multiple_time_does_not_mutate_locals_multiple_time
assert len(a_locals) == 2
+def test_getattr_fails_on_empty_values():
+ code = """
+ import collections
+ collections
+ """
+ node = extract_node(code)
+ inferred = next(node.infer())
+ with pytest.raises(exceptions.InferenceError):
+ next(inferred.igetattr(""))
+
+ with pytest.raises(exceptions.AttributeInferenceError):
+ inferred.getattr("")
+
+
if __name__ == "__main__":
unittest.main()