[Python-checkins] bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)

miss-islington webhook-mailer at python.org
Wed Jan 12 20:46:39 EST 2022


https://github.com/python/cpython/commit/d9101c4e49dc29f21319493818130ad5468402a2
commit: d9101c4e49dc29f21319493818130ad5468402a2
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-01-12T17:46:35-08:00
summary:

bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)

(cherry picked from commit 1de60155d5d01be2924e72fb68dd13d4fd00acd7)

Co-authored-by: Nikita Sobolev <mail at sobolevn.me>

files:
M Lib/test/test_typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 19c38ec833c67..8cdb1166c847f 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -2943,6 +2943,12 @@ def test_get_type_hints_classes(self):
                           'my_inner_a2': mod_generics_cache.B.A,
                           'my_outer_a': mod_generics_cache.A})
 
+    def test_get_type_hints_classes_no_implicit_optional(self):
+        class WithNoneDefault:
+            field: int = None  # most type-checkers won't be happy with it
+
+        self.assertEqual(gth(WithNoneDefault), {'field': int})
+
     def test_respect_no_type_check(self):
         @no_type_check
         class NoTpCheck:



More information about the Python-checkins mailing list