8000 Materials for Python Copy [UPDATE] · realpython/materials@c94fb3a · GitHub
[go: up one dir, main page]

Skip to content

Commit c94fb3a

Browse files
committed
Materials for Python Copy [UPDATE]
1 parent 509455a commit c94fb3a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

python-copy/person.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def __replace__(self, **changes):
5656
person_copy = copy.replace(person, age=24, name="Alice Smith")
5757

5858
vars_slots = lambda obj: {
59-
name: getattr(obj, name)
60-
for name in obj.__slots__
59+
name: getattr(obj, name) for name in obj.__slots__
6160
}
6261

6362
print(vars_slots(person))
@@ -84,7 +83,9 @@ def __replace__(self, **changes):
8483
setattr(instance, name, value)
8584

8685
if age and dob:
87-
raise AttributeError("can't set both 'age' and 'date_of_birth'")
86+
raise AttributeError(
87+
"can't set both 'age' and 'date_of_birth'"
88+
)
8889
elif age:
8990
dob = copy.replace(date.today(), year=date.today().year - age)
9091
instance.date_of_birth = dob

0 commit comments

Comments
 (0)
0