forked from bedroombuilds/python2rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_args.py
More file actions
44 lines (33 loc) · 995 Bytes
/
default_args.py
File metadata and controls
44 lines (33 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from dataclasses import dataclass
class User:
def __init__(self, uid, email, first_name=None, last_name=None):
self.id = uid
self.email = email
self.first_name = first_name
self.last_name = last_name
def complete(self):
return self.last_name is not None \
and self.id > 0 \
and not self.email.empty() \
and self.first_name is not None
@dataclass
class Channel:
token: int = 0
special_info: str = ''
class ChannelBuilder:
def __init__(self):
self.token = 0
self.special_info = '42'
def build(self):
return Channel(self.token, self.special_info)
if __name__ == '__main__':
bob = User(13, "bob@example.com")
bob.first_name = "Bob"
print("complete?", bob.complete())
print("bob_the_builder", bob)
cb = ChannelBuilder()
cb.special_info = "84"
c1 = cb.build()
c2 = Channel(4321)
print(c1, c2)
print(c1.token, c2.special_info)