summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2020-11-22 15:04:12 +0100
committerhippo91 <guillaume.peillex@gmail.com>2020-11-22 15:04:12 +0100
commit736930cc28d37d7a79a26123f4a93f1e77d761fb (patch)
treeb0326cd1cb7daa11341eb115bac96122758eb45c
parent8dafae9732bd4f3c16c4472952dfcb98dded5a78 (diff)
downloadastroid-git-736930cc28d37d7a79a26123f4a93f1e77d761fb.tar.gz
Thanks to the preceeding commit the inference is more precise for class decorated with dataclasses
-rw-r--r--tests/unittest_inference.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index b7bc732d..25f8b8e6 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -5667,6 +5667,10 @@ def test_custom_decorators_for_classmethod_and_staticmethods(code, obj, obj_type
@pytest.mark.skipif(sys.version_info < (3, 8), reason="Needs dataclasses available")
+@pytest.mark.skipif(
+ sys.version_info >= (3, 9),
+ reason="Exact inference with dataclasses (replace function) in python3.9",
+)
def test_dataclasses_subscript_inference_recursion_error():
code = """
from dataclasses import dataclass, replace
@@ -5687,6 +5691,31 @@ def test_dataclasses_subscript_inference_recursion_error():
assert helpers.safe_infer(node) is None
+@pytest.mark.skipif(
+ sys.version_info < (3, 9),
+ reason="Exact inference with dataclasses (replace function) in python3.9",
+)
+def test_dataclasses_subscript_inference_recursion_error_39():
+ code = """
+ from dataclasses import dataclass, replace
+
+ @dataclass
+ class ProxyConfig:
+ auth: str = "/auth"
+
+
+ a = ProxyConfig("")
+ test_dict = {"proxy" : {"auth" : "", "bla" : "f"}}
+
+ foo = test_dict['proxy']
+ replace(a, **test_dict['proxy']) # This fails
+ """
+ node = extract_node(code)
+ infer_val = helpers.safe_infer(node)
+ assert isinstance(infer_val, Instance)
+ assert infer_val.pytype() == ".ProxyConfig"
+
+
def test_self_reference_infer_does_not_trigger_recursion_error():
# Prevents https://github.com/PyCQA/pylint/issues/1285
code = """