Skip to content

Commit b3e15c7

Browse files
committed
added a second way of accomplishing the same effect
1 parent 6f1bff4 commit b3e15c7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

06-decorators.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def wrapper(cls):
2828
return wrapper
2929

3030

31+
def simple_type_check(cls):
32+
for var_name, checker in cls.__dict__.items():
33+
if isinstance(checker, TypeChecker):
34+
checker.name = var_name
35+
return cls
36+
37+
3138
@type_check(x=IntType, y=IntType)
3239
class Point:
3340
def __init__(self, x, y):
@@ -49,8 +56,11 @@ class PointType(TypeChecker):
4956
required_type = Point
5057

5158

52-
@type_check(center=PointType, radius=IntType)
59+
@simple_type_check
5360
class Circle:
61+
center = PointType()
62+
radius = IntType()
63+
5464
def __init__(self, center, radius):
5565
self.center = center
5666
self.radius = radius

0 commit comments

Comments
 (0)