Skip to content

Commit 313bb85

Browse files
author
Sylvain MARIE
committed
Fixed issue with python 2
1 parent 1cc4728 commit 313bb85

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

valid8/composition.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import abstractmethod
22
from collections import OrderedDict
3+
from sys import version_info
34

45
from makefun import with_signature
56

@@ -11,24 +12,24 @@
1112
try: # python 3.5.3-
1213
from typing import Type
1314
except ImportError:
14-
pass
15-
16-
try:
17-
from mini_lambda import x
18-
CallableType = Union[Callable, type(x)]
19-
except ImportError:
20-
CallableType = Callable
15+
use_typing = False
16+
else:
17+
try:
18+
from mini_lambda import x
19+
CallableType = Union[Callable, type(x)]
20+
except ImportError:
21+
CallableType = Callable
2122

22-
CallableAndFailureTuple = Tuple[CallableType, Union[str, 'Type[Failure]']]
23-
""" Represents the allowed construct to define a failure raiser from a validation function: a tuple """
23+
CallableAndFailureTuple = Tuple[CallableType, Union[str, 'Type[Failure]']]
24+
""" Represents the allowed construct to define a failure raiser from a validation function: a tuple """
2425

25-
ValidationFunc = Union[CallableType, CallableAndFailureTuple]
26-
""" Represents the 'typing' type for a single validation function """
26+
ValidationFunc = Union[CallableType, CallableAndFailureTuple]
27+
""" Represents the 'typing' type for a single validation function """
2728

28-
ValidationFuncs = Union[ValidationFunc, List['ValidationFuncs']] # recursion is used here ('forward reference')
29-
""" Represents the 'typing' type for 'validation_func' arguments in the various methods """
29+
ValidationFuncs = Union[ValidationFunc, List['ValidationFuncs']] # recursion is used here ('forward reference')
30+
""" Represents the 'typing' type for 'validation_func' arguments in the various methods """
3031

31-
use_typing = True
32+
use_typing = version_info > (3, 0)
3233

3334
except TypeError:
3435
# this happens with python 3.5.2: typing has an issue.

valid8/entry_points.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
try: # python 3.5.3-
1010
from typing import Type
1111
except ImportError:
12-
pass
13-
from valid8.composition import ValidationFuncs
14-
use_typing = True
12+
use_typing = False
13+
else:
14+
from valid8.composition import ValidationFuncs
15+
use_typing = sys.version_info > (3, 0)
1516
except ImportError:
1617
use_typing = False
1718

valid8/entry_points_annotations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
try: # python 3.5.3-
99
from typing import Type
1010
except ImportError:
11-
pass
12-
from valid8.composition import ValidationFuncs
13-
use_typing = True
11+
use_typing = False
12+
else:
13+
from valid8.composition import ValidationFuncs
14+
use_typing = sys.version_info > (3, 0)
1415
except ImportError:
1516
use_typing = False
1617

0 commit comments

Comments
 (0)