5
5
Module that contains wrappers and shortcuts (aliases).
6
6
"""
7
7
import warnings
8
+ import six
8
9
9
10
from django_dynamic_fixture .ddf import DynamicFixture , Copier , DDFLibrary , \
10
11
set_pre_save_receiver , set_post_save_receiver
@@ -57,7 +58,8 @@ def fixture(**kwargs):
57
58
58
59
59
60
# Wrappers
60
- def new (model , n = 1 , lesson = None , persist_dependencies = True , ** kwargs ):
61
+
62
+ def _new (model , n = 1 , lesson = None , persist_dependencies = True , ** kwargs ):
61
63
"""
62
64
Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
63
65
All instances will NOT be persisted in the database, except its dependencies, in case @persist_dependencies is True.
@@ -87,7 +89,7 @@ def new(model, n=1, lesson=None, persist_dependencies=True, **kwargs):
87
89
return instances
88
90
89
91
90
- def get (model , n = 1 , lesson = None , ** kwargs ):
92
+ def _get (model , n = 1 , lesson = None , ** kwargs ):
91
93
"""
92
94
Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
93
95
All instances will be persisted in the database.
@@ -116,7 +118,7 @@ def get(model, n=1, lesson=None, **kwargs):
116
118
return instances
117
119
118
120
119
- def teach (model , lesson = None , ** kwargs ):
121
+ def _teach (model , lesson = None , ** kwargs ):
120
122
'''
121
123
@model: The class of the Django model.
122
124
@lesson: Name of custom lesson to be created.
@@ -140,11 +142,37 @@ def teach(model, lesson=None, **kwargs):
140
142
141
143
142
144
# Shortcuts
143
- N = new
144
- G = get
145
+ N = new = _new
146
+ G = get = _get
147
+ T = teach = _teach
145
148
F = fixture
146
149
C = Copier
147
150
P = print_field_values
148
151
DDFLibrary = DDFLibrary
149
152
PRE_SAVE = set_pre_save_receiver
150
153
POST_SAVE = set_post_save_receiver
154
+
155
+ if six .PY3 :
156
+ # Add type hints for Python >= 3.5
157
+ try :
158
+ import typing
159
+
160
+ INSTANCE_TYPE = typing .TypeVar ('INSTANCE' )
161
+
162
+ hack_to_avoid_py2_syntax_errors = '''
163
+ def new(model: typing.Type[INSTANCE_TYPE], n=1, lesson=None, persist_dependencies=True, **kwargs) -> INSTANCE_TYPE:
164
+ return _new(model, n=n, lesson=lesson, persist_dependencies=persist_dependencies, **kwargs)
165
+
166
+ def get(model: typing.Type[INSTANCE_TYPE], n=1, lesson=None, **kwargs) -> INSTANCE_TYPE:
167
+ return _get(model, n=n, lesson=lesson, **kwargs)
168
+
169
+ def teach(model: typing.Type[INSTANCE_TYPE], lesson=None, **kwargs):
170
+ return _teach(model, lesson=lesson, **kwargs)
171
+
172
+ N = new
173
+ G = get
174
+ T = teach
175
+ '''
176
+ exec (hack_to_avoid_py2_syntax_errors )
177
+ except (ImportError , SyntaxError ) as e :
178
+ pass
0 commit comments