summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhanosmantaskaya@gmail.com>2020-10-21 13:49:22 (GMT)
committerGitHub <noreply@github.com>2020-10-21 13:49:22 (GMT)
commitc7437e2c0216e05fbf17bf96294cb20954e36e48 (patch)
tree6ac5b43803a48f26fae2b3992a9aa0fff958a3fc /Lib/dataclasses.py
parent9a1ad2cf02e52eccc3204e43752c8742d4c77f6b (diff)
downloadcpython-c7437e2c0216e05fbf17bf96294cb20954e36e48.zip
cpython-c7437e2c0216e05fbf17bf96294cb20954e36e48.tar.gz
cpython-c7437e2c0216e05fbf17bf96294cb20954e36e48.tar.bz2
bpo-41747: Ensure all dataclass methods uses their parents' qualname (GH-22155)
* bpo-41747: Ensure all dataclass methods uses their parents' qualname Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index adfb9b7..0c4b475 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -8,7 +8,7 @@ import builtins
import functools
import abc
import _thread
-from types import GenericAlias
+from types import FunctionType, GenericAlias
__all__ = ['dataclass',
@@ -757,12 +757,19 @@ def _get_field(cls, a_name, a_type):
return f
+def _set_qualname(cls, value):
+ # Ensure that the functions returned from _create_fn uses the proper
+ # __qualname__ (the class they belong to).
+ if isinstance(value, FunctionType):
+ value.__qualname__ = f"{cls.__qualname__}.{value.__name__}"
+ return value
def _set_new_attribute(cls, name, value):
# Never overwrites an existing attribute. Returns True if the
# attribute already exists.
if name in cls.__dict__:
return True
+ _set_qualname(cls, value)
setattr(cls, name, value)
return False
@@ -777,7 +784,7 @@ def _hash_set_none(cls, fields, globals):
def _hash_add(cls, fields, globals):
flds = [f for f in fields if (f.compare if f.hash is None else f.hash)]
- return _hash_fn(flds, globals)
+ return _set_qualname(cls, _hash_fn(flds, globals))
def _hash_exception(cls, fields, globals):
# Raise an exception.