]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
dataclasses: Avoid using private class (#124465)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 24 Sep 2024 21:02:18 +0000 (14:02 -0700)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 21:02:18 +0000 (14:02 -0700)
typing.get_origin() does what we need here, without reaching into
typing internals. This shouldn't change any behavior (so I am going
to skip news), but it sets a good example for other users introspecting
typing objects.

Lib/dataclasses.py

index ac7d40cf2cac2edae1c14e8564834360ac9259f1..6255d8980974e0c70a65d73d0b32ba720f74107a 100644 (file)
@@ -690,11 +690,8 @@ def _frozen_get_del_attr(cls, fields, func_builder):
 
 
 def _is_classvar(a_type, typing):
-    # This test uses a typing internal class, but it's the best way to
-    # test if this is a ClassVar.
     return (a_type is typing.ClassVar
-            or (type(a_type) is typing._GenericAlias
-                and a_type.__origin__ is typing.ClassVar))
+            or (typing.get_origin(a_type) is typing.ClassVar))
 
 
 def _is_initvar(a_type, dataclasses):