Skip to content

Commit

Permalink
dataclasses: Avoid using private class (python#124465)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JelleZijlstra committed Sep 24, 2024
1 parent 5a60566 commit 950fab4
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 950fab4

Please sign in to comment.