-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_overload.py
More file actions
32 lines (23 loc) 路 936 Bytes
/
Copy pathtest_overload.py
File metadata and controls
32 lines (23 loc) 路 936 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
from luxtools.functional import overload
def test_class_types():
class Email:
def __init__(self, email: str):
self.email = email
def __str__(self) -> str:
return self.email
class PhoneNumber:
def __init__(self, phone_number: str):
self.phone_number = phone_number
def __str__(self) -> str:
return self.phone_number
# problem: the function is not in global scope.
@overload(scope=locals())
def get_user(email: Email):
return "email function"
@overload(scope=locals())
def get_user(phone_number: PhoneNumber):
return "phone function"
user_email = get_user(Email("test@example.com"))
user_phone = get_user(PhoneNumber("123-456-789"))
assert user_email == "email function", "should be sent to the email function"
assert user_phone == "phone function", "should be sent to the phone function"