summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2018-05-14 21:16:52 (GMT)
committerGitHub <noreply@github.com>2018-05-14 21:16:52 (GMT)
commit3059042410dce69806b94be72d5c8055d616f3a3 (patch)
treec5159a0e2b608d32526b74d92ea0d53f8079cf98
parent00717a46a120dd8c8c74970fd75d201a5f42ab18 (diff)
downloadcpython-3059042410dce69806b94be72d5c8055d616f3a3.zip
cpython-3059042410dce69806b94be72d5c8055d616f3a3.tar.gz
cpython-3059042410dce69806b94be72d5c8055d616f3a3.tar.bz2
bpo-33502: dataclass._Dataclassparams repr: use repr of each member. (GH-6812)
-rw-r--r--Lib/dataclasses.py12
-rw-r--r--f.py12
-rw-r--r--j.py15
-rw-r--r--t.py20
-rw-r--r--x.py31
5 files changed, 84 insertions, 6 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index c60eeaa..2ce6a02 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -274,12 +274,12 @@ class _DataclassParams:
def __repr__(self):
return ('_DataclassParams('
- f'init={self.init},'
- f'repr={self.repr},'
- f'eq={self.eq},'
- f'order={self.order},'
- f'unsafe_hash={self.unsafe_hash},'
- f'frozen={self.frozen}'
+ f'init={self.init!r},'
+ f'repr={self.repr!r},'
+ f'eq={self.eq!r},'
+ f'order={self.order!r},'
+ f'unsafe_hash={self.unsafe_hash!r},'
+ f'frozen={self.frozen!r}'
')')
diff --git a/f.py b/f.py
new file mode 100644
index 0000000..02a3668
--- /dev/null
+++ b/f.py
@@ -0,0 +1,12 @@
+from __future__ import annotations
+from dataclasses import dataclass
+from typing import List
+from typing import ClassVar as CV
+
+@dataclass
+class A:
+ a: List[str]
+
+@dataclass
+class B(A):
+ b: CV[int]
diff --git a/j.py b/j.py
new file mode 100644
index 0000000..9551702
--- /dev/null
+++ b/j.py
@@ -0,0 +1,15 @@
+
+class X:
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return str(self.value)
+ def __format__(self, fmt):
+ assert fmt[0] == '='
+ self.value = eval(fmt[1:])
+ return ''
+
+x = X(3)
+print(x)
+f'{x:=4}' # Behold!
+print(x)
diff --git a/t.py b/t.py
new file mode 100644
index 0000000..7484cf9
--- /dev/null
+++ b/t.py
@@ -0,0 +1,20 @@
+from dataclasses import *
+
+class D:
+ """A descriptor class that knows its name."""
+ def __set_name__(self, owner, name):
+ self.name = name
+ def __get__(self, instance, owner):
+ if instance is not None:
+ return 1
+ return self
+
+from dataclasses import *
+
+@dataclass
+class C:
+ d: int = field(default=D(), init=False)
+
+@dataclass
+class E(C):
+ e: int = field(default=D(), init=False)
diff --git a/x.py b/x.py
new file mode 100644
index 0000000..2b78f3e
--- /dev/null
+++ b/x.py
@@ -0,0 +1,31 @@
+#from __future__ import annotations
+from typing import ClassVar, Dict, get_type_hints
+from dataclasses import *
+
+class Starship:
+ stats: ClassVar[Dict[str, int]] = {}
+
+#print(get_type_hints(Starship))
+
+#class A:
+# a: Dict[int, C]
+
+#print(get_type_hints(A))
+
+cv = [ClassVar[int]]
+
+@dataclass
+class C:
+ CVS = [ClassVar[str]]
+ a: cv[0]
+ b: 'C'
+ c: 'CVS[0]'
+ x: 'ClassVar["int"]'
+ y: 'ClassVar[C]'
+
+print()
+print(C.__annotations__)
+print(C.__dataclass_fields__)
+
+
+#print(get_type_hints(C))