diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-09-24 21:02:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 21:02:18 (GMT) |
commit | 950fab46ad3a1960aa289d2d1de55447b88e25d7 (patch) | |
tree | 5656626c045aa4b4c217b2fc4c7f356afd5943f3 | |
parent | 5a605660745d32a9b9f4208666889c702527208c (diff) | |
download | cpython-950fab46ad3a1960aa289d2d1de55447b88e25d7.zip cpython-950fab46ad3a1960aa289d2d1de55447b88e25d7.tar.gz cpython-950fab46ad3a1960aa289d2d1de55447b88e25d7.tar.bz2 |
dataclasses: Avoid using private class (#124465)
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.
-rw-r--r-- | Lib/dataclasses.py | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index ac7d40c..6255d89 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -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): |