Skip to content

Commit 3821e1e

Browse files
author
Sylvain MARIE
committed
Python 3.5.2 fix. Fixes #30
1 parent 696f1a4 commit 3821e1e

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

valid8/composition.py

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

54
from makefun import with_signature
65

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

31+
use_typing = True
32+
3233
except TypeError:
3334
# this happens with python 3.5.2: typing has an issue.
34-
pass
35+
use_typing = False
36+
3537
except ImportError:
36-
pass
38+
use_typing = False
3739

3840

3941
supported_syntax = 'a callable, a tuple(callable, help_msg_str), a tuple(callable, failure_type), or a list of ' \
@@ -428,7 +430,7 @@ def xor_v_(x):
428430

429431

430432
# Python 3+: load the 'more explicit api'
431-
if version_info >= (3, 0):
433+
if use_typing:
432434
new_sig = """(*validation_func: ValidationFuncs,
433435
catch_all: bool = False) -> Callable"""
434436
else:
@@ -462,7 +464,7 @@ def not_all(*validation_func, # type: ValidationFuncs
462464

463465

464466
# Python 3+: load the 'more explicit api'
465-
if version_info >= (3, 0):
467+
if use_typing:
466468
new_sig = """(*validation_func: ValidationFuncs,
467469
failure_type: 'Type[WrappingFailure]' = None,
468470
help_msg: str = None,

valid8/entry_points.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
from copy import copy
3-
from sys import version_info
43

54
from makefun import with_signature
65
from six import with_metaclass
@@ -12,8 +11,9 @@
1211
except ImportError:
1312
pass
1413
from valid8.composition import ValidationFuncs
14+
use_typing = True
1515
except ImportError:
16-
pass
16+
use_typing = False
1717

1818
from valid8.utils_string import end_with_dot
1919
from valid8.base import result_is_success, get_callable_name, _none_accepter, _none_rejecter, RootException, \
@@ -370,7 +370,7 @@ class new_error_type(with_metaclass(MetaReprForValidator, error_type, additional
370370

371371

372372
# Python 3+: load the 'more explicit api'
373-
if version_info >= (3, 0):
373+
if use_typing:
374374
new_sig = """(self,
375375
*validation_func: ValidationFuncs,
376376
error_type: 'Type[ValidationError]' = None,
@@ -653,7 +653,7 @@ def is_valid(self,
653653

654654

655655
# Python 3+: load the 'more explicit api'
656-
if version_info >= (3, 0):
656+
if use_typing:
657657
new_sig = """(name: str,
658658
value: Any,
659659
*validation_func: ValidationFuncs,
@@ -712,7 +712,7 @@ def assert_valid(name, # type: str
712712

713713

714714
# Python 3+: load the 'more explicit api'
715-
if version_info >= (3, 0):
715+
if use_typing:
716716
new_sig = """(value,
717717
*validation_func: Union[Callable, List[Callable]],
718718
none_policy: int=None):"""

valid8/entry_points_annotations.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
from inspect import ismethod, isclass
3-
from sys import version_info
43

54
from decopatch import class_decorator, function_decorator, DECORATED
65

@@ -11,8 +10,9 @@
1110
except ImportError:
1211
pass
1312
from valid8.composition import ValidationFuncs
13+
use_typing = True
1414
except ImportError:
15-
pass
15+
use_typing = False
1616

1717
try:
1818
from inspect import signature, Signature
@@ -91,7 +91,7 @@ def get_variable_str(self):
9191

9292

9393
# Python 3+: load the 'more explicit api'
94-
if version_info >= (3, 0):
94+
if use_typing:
9595
new_sig = """(self,
9696
validated_func: Callable,
9797
*validation_func: ValidationFuncs,
@@ -255,7 +255,7 @@ def assert_valid(self,
255255

256256

257257
# Python 3+: load the 'more explicit api'
258-
if version_info >= (3, 0):
258+
if use_typing:
259259
new_sig = """(self,
260260
validated_class: Callable,
261261
validated_field_name: str,
@@ -335,7 +335,7 @@ def get_validated_class_display_name(self):
335335

336336

337337
# Python 3+: load the 'more explicit api'
338-
if version_info >= (3, 0):
338+
if use_typing:
339339
new_sig = """(cls,
340340
field_name,
341341
*validation_func: ValidationFuncs,
@@ -425,7 +425,7 @@ def myfunc(a, b):
425425

426426

427427
# Python 3+: load the 'more explicit api'
428-
if version_info >= (3, 0):
428+
if use_typing:
429429
new_sig = """(f,
430430
arg_name,
431431
*validation_func: ValidationFuncs,
@@ -470,7 +470,7 @@ def validate_arg(f,
470470

471471

472472
# Python 3+: load the 'more explicit api'
473-
if version_info >= (3, 0):
473+
if use_typing:
474474
new_sig = """(*validation_func: ValidationFuncs,
475475
help_msg: str = None,
476476
error_type: 'Type[OutputValidationError]' = None,
@@ -509,7 +509,7 @@ def decorate(f):
509509

510510

511511
# Python 3+: load the 'more explicit api'
512-
if version_info >= (3, 0):
512+
if use_typing:
513513
new_sig = """(cls,
514514
field_name: str,
515515
*validation_func: ValidationFuncs,
@@ -697,7 +697,7 @@ def decorate_several_with_validation(func,
697697

698698

699699
# Python 3+: load the 'more explicit api'
700-
if version_info >= (3, 0):
700+
if use_typing:
701701
new_sig = """(func,
702702
arg_name: str,
703703
*validation_func: ValidationFuncs,
@@ -801,7 +801,7 @@ class fields)"""
801801

802802

803803
# Python 3+: load the 'more explicit api'
804-
if version_info >= (3, 0):
804+
if use_typing:
805805
new_sig = """(validated_func: Callable,
806806
s: Signature,
807807
arg_name: str,

0 commit comments

Comments
 (0)