[Python-checkins] bpo-46437: remove useless `hasattr` from `test_typing` (GH-30704)

miss-islington webhook-mailer at python.org
Wed Jan 19 17:12:32 EST 2022


https://github.com/python/cpython/commit/3b51926ee9838e746a5cdb08c7eb985646bd133c
commit: 3b51926ee9838e746a5cdb08c7eb985646bd133c
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-19T14:12:25-08:00
summary:

bpo-46437: remove useless `hasattr` from `test_typing` (GH-30704)

(cherry picked from commit 263c0dd16017613c5ea2fbfc270be4de2b41b5ad)

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 cb6be2cee87d7..17da4b81f5193 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -3230,11 +3230,10 @@ def test_container(self):
         self.assertNotIsInstance(42, typing.Container)
 
     def test_collection(self):
-        if hasattr(typing, 'Collection'):
-            self.assertIsInstance(tuple(), typing.Collection)
-            self.assertIsInstance(frozenset(), typing.Collection)
-            self.assertIsSubclass(dict, typing.Collection)
-            self.assertNotIsInstance(42, typing.Collection)
+        self.assertIsInstance(tuple(), typing.Collection)
+        self.assertIsInstance(frozenset(), typing.Collection)
+        self.assertIsSubclass(dict, typing.Collection)
+        self.assertNotIsInstance(42, typing.Collection)
 
     def test_abstractset(self):
         self.assertIsInstance(set(), typing.AbstractSet)
@@ -4321,8 +4320,9 @@ def test_all(self):
         self.assertIn('ValuesView', a)
         self.assertIn('cast', a)
         self.assertIn('overload', a)
-        if hasattr(contextlib, 'AbstractContextManager'):
-            self.assertIn('ContextManager', a)
+        # Context managers.
+        self.assertIn('ContextManager', a)
+        self.assertIn('AsyncContextManager', a)
         # Check that io and re are not exported.
         self.assertNotIn('io', a)
         self.assertNotIn('re', a)
@@ -4336,8 +4336,6 @@ def test_all(self):
         self.assertIn('SupportsComplex', a)
 
     def test_all_exported_names(self):
-        import typing
-
         actual_all = set(typing.__all__)
         computed_all = {
             k for k, v in vars(typing).items()



More information about the Python-checkins mailing list