@@ -42,7 +42,8 @@ class Wall(object):
4242 assert vars (w ) == {'color' : 'white' , 'height' : 12 }
4343
4444
45- def test_default_factory ():
45+ @pytest .mark .parametrize ("use_decorator" , [False , True ], ids = "use_decorator={}" .format )
46+ def test_default_factory (use_decorator ):
4647
4748 class BadPocket (object ):
4849 items = field (default = [])
@@ -52,8 +53,16 @@ class BadPocket(object):
5253 g = BadPocket ()
5354 assert g .items == ['thing' ]
5455
55- class Pocket (object ):
56- items = field (default_factory = lambda obj : [])
56+ if use_decorator :
57+ class Pocket :
58+ items = field ()
59+
60+ @items .default_factory
61+ def default_items (self ):
62+ return []
63+ else :
64+ class Pocket (object ):
65+ items = field (default_factory = lambda obj : [])
5766
5867 p = Pocket ()
5968 g = Pocket ()
@@ -62,19 +71,6 @@ class Pocket(object):
6271 assert g .items == []
6372
6473
65- class Pocket (object ):
66- items = field (default_factory = lambda obj : [])
67-
68-
69- class Wall (object ):
70- height = field (doc = "Height of the wall in mm." ) # type: int
71- color = field (default = 'white' , doc = "Color of the wall." ) # type: str
72- secondary_color = field (default_factory = copy_field (color ), doc = "Color of the wall." ) # type: str
73-
74- w = Wall ()
75- w .height
76-
77-
7874@pytest .mark .parametrize ("py36_style_type_hints" , [False , True ], ids = "py36_style_type_hints={}" .format )
7975def test_type_validation (py36_style_type_hints ):
8076 if py36_style_type_hints :
0 commit comments