From 6094fc46d12904eaec42c3e622645551b549e7e5 Mon Sep 17 00:00:00 2001 From: Charlie Denton Date: Sun, 12 Mar 2023 23:25:29 +0000 Subject: [PATCH] Prove possibly-undefined errors disappear This test fails with the error: AssertionError: Command 3 (dmypy check -- bar.py) did not give expected output --- Captured stderr call --- Expected: bar.py:4: error: Name "a" may be undefined [possibly-undefined] (diff) == Return code: 1 (diff) Actual: (empty) This test illustrates that possibly-undefined errors currently disappear in the same way that 'Unused "type: ignore"' errors do as described in #9655. Ref: https://github.com/python/mypy/issues/9655 --- test-data/unit/daemon.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test-data/unit/daemon.test b/test-data/unit/daemon.test index dcc7ec86309f0..d4ec103db8818 100644 --- a/test-data/unit/daemon.test +++ b/test-data/unit/daemon.test @@ -556,3 +556,22 @@ bar.py:2: error: "type: ignore" comment without error code [ignore-without-code [file bar.py] from foo.empty import * a = 1 # type: ignore + +[case testPossiblyUndefinedVarsPreservedAfterUpdate] +-- Regression test for https://github.com/python/mypy/issues/9655 +$ dmypy start -- --enable-error-code possibly-undefined --no-error-summary +Daemon started +$ dmypy check -- bar.py +bar.py:4: error: Name "a" may be undefined [possibly-undefined] +== Return code: 1 +$ dmypy check -- bar.py +bar.py:4: error: Name "a" may be undefined [possibly-undefined] +== Return code: 1 + +[file foo/__init__.py] +[file foo/empty.py] +[file bar.py] +from foo.empty import * +if False: + a = 1 +a