From a6738cdedecfce7404565902b6247f34e0f7077d Mon Sep 17 00:00:00 2001 From: roselyn Date: Wed, 11 Nov 2026 12:13:21 +0000 Subject: [PATCH] Allow unittest.assertIsNone() and unittest.AssertIsNotNone() to narrow types --- stdlib/unittest/case.pyi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stdlib/unittest/case.pyi b/stdlib/unittest/case.pyi index 1d1206b7fc36..7c8b77f39b79 100644 --- a/stdlib/unittest/case.pyi +++ b/stdlib/unittest/case.pyi @@ -102,8 +102,17 @@ class TestCase: def assertFalse(self, expr: Any, msg: Any = None) -> None: ... def assertIs(self, expr1: object, expr2: object, msg: Any = None) -> None: ... def assertIsNot(self, expr1: object, expr2: object, msg: Any = None) -> None: ... - def assertIsNone(self, obj: object, msg: Any = None) -> None: ... + + @overload + def assertIsNone(self, obj: None, msg: Any = None) -> None: ... + @overload + def assertIsNone(self, obj: object, msg: Any = None) -> Never: ... + + @overload + def assertIsNotNone(self, obj: None, msg: Any = None) -> Never: ... + @overload def assertIsNotNone(self, obj: object, msg: Any = None) -> None: ... + def assertIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = None) -> None: ... def assertNotIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = None) -> None: ... def assertIsInstance(self, obj: object, cls: _ClassInfo, msg: Any = None) -> None: ...