Skip to content

Commit

Permalink
bpo-33502: dataclass._Dataclassparams repr: use repr of each member. (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvsmith committed May 14, 2018
1 parent 00717a4 commit 3059042
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lib/dataclasses.py
Expand Up @@ -274,12 +274,12 @@ def __init__(self, init, repr, eq, order, unsafe_hash, frozen):

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}'
')')


Expand Down
12 changes: 12 additions & 0 deletions 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]
15 changes: 15 additions & 0 deletions 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)
20 changes: 20 additions & 0 deletions 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)
31 changes: 31 additions & 0 deletions 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))

0 comments on commit 3059042

Please sign in to comment.