From 2b1bba258d3678b3152476e52bd01040337c4ca3 Mon Sep 17 00:00:00 2001 From: Bagou Ines Date: Thu, 9 Oct 2025 10:43:29 +0200 Subject: [PATCH 1/3] ajout du test unitaire issue_scope.test --- test-data/unit/issue_scope.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test-data/unit/issue_scope.test diff --git a/test-data/unit/issue_scope.test b/test-data/unit/issue_scope.test new file mode 100644 index 000000000000..2ea013dd4e62 --- /dev/null +++ b/test-data/unit/issue_scope.test @@ -0,0 +1,17 @@ +[case testScopeOptionalIntResolution] +from typing import Optional + +x: Optional[int] = None +y: Optional[int] = None + +def f() -> None: + x = 1 + y = 1 + class C: + reveal_type(x) # should be int + reveal_type(y) # should be Optional[int] + x = 2 + +[out] +note: Revealed type is "builtins.int" +note: Revealed type is "Union[builtins.int, None]" From 5998612b756ac370a74d3d0c761bb211e0cd0b2c Mon Sep 17 00:00:00 2001 From: Bagou Ines Date: Mon, 8 Dec 2025 08:50:41 +0100 Subject: [PATCH 2/3] modification de semanal.py --- mypy/nested-class-scope.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 mypy/nested-class-scope.py diff --git a/mypy/nested-class-scope.py b/mypy/nested-class-scope.py new file mode 100644 index 000000000000..d3194aeccade --- /dev/null +++ b/mypy/nested-class-scope.py @@ -0,0 +1,12 @@ +from typing import * + +x: Optional[int] = None +y: Optional[int] = None + +def f() -> None: + x = 1 + y = 1 + class C: + reveal_type(x) # Incorrectly reveals int, should be Optional[int] + reveal_type(y) # Correctly reveals int + x = 2 \ No newline at end of file From 6c16e3d03bffb15b9c7314731ab6de811e66a4f6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Dec 2025 08:00:20 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/nested-class-scope.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/nested-class-scope.py b/mypy/nested-class-scope.py index d3194aeccade..c2333f74f04a 100644 --- a/mypy/nested-class-scope.py +++ b/mypy/nested-class-scope.py @@ -3,10 +3,12 @@ x: Optional[int] = None y: Optional[int] = None + def f() -> None: x = 1 y = 1 + class C: reveal_type(x) # Incorrectly reveals int, should be Optional[int] reveal_type(y) # Correctly reveals int - x = 2 \ No newline at end of file + x = 2