Skip to content

Commit 7c052ae

Browse files
committed
[fix] Hacking to avoid syntax errors in Python 2
1 parent 90ccfea commit 7c052ae

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

django_dynamic_fixture/__init__.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,20 @@ def _teach(model, lesson=None, **kwargs):
159159

160160
INSTANCE_TYPE = typing.TypeVar('INSTANCE')
161161

162-
def new(model: typing.Type[INSTANCE_TYPE], n=1, lesson=None, persist_dependencies=True, **kwargs) -> INSTANCE_TYPE:
163-
return _new(model, n=n, lesson=lesson, persist_dependencies=persist_dependencies, **kwargs)
164-
165-
def get(model: typing.Type[INSTANCE_TYPE], n=1, lesson=None, **kwargs) -> INSTANCE_TYPE:
166-
return _get(model, n=n, lesson=lesson, **kwargs)
167-
168-
def teach(model: typing.Type[INSTANCE_TYPE], lesson=None, **kwargs):
169-
return _teach(model, lesson=lesson, **kwargs)
170-
171-
N = new
172-
G = get
173-
T = teach
174-
except (ImportError, SyntaxError):
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:
175178
pass

0 commit comments

Comments
 (0)