Skip to content

Commit 8d28131

Browse files
ambvilevkivskyi
authored andcommitted
Fix if statements with ambiguously indented bodies (#360)
Since this was related to the same lines in conditions, also fixed binary operators on line beginnings.
1 parent 1830f2e commit 8d28131

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

python2/typing.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,17 @@ def _type_check(arg, msg):
328328
return type(None)
329329
if isinstance(arg, basestring):
330330
arg = _ForwardRef(arg)
331-
if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or
332-
not isinstance(arg, (type, _TypingBase)) and not callable(arg)):
331+
if (
332+
isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or
333+
not isinstance(arg, (type, _TypingBase)) and not callable(arg)
334+
):
333335
raise TypeError(msg + " Got %.100r." % (arg,))
334336
# Bare Union etc. are not valid as type arguments
335-
if (type(arg).__name__ in ('_Union', '_Optional')
336-
and not getattr(arg, '__origin__', None)
337-
or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)):
337+
if (
338+
type(arg).__name__ in ('_Union', '_Optional') and
339+
not getattr(arg, '__origin__', None) or
340+
isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)
341+
):
338342
raise TypeError("Plain %s is not valid as type argument" % arg)
339343
return arg
340344

@@ -929,8 +933,10 @@ def _valid_for_check(cls):
929933
if cls is Generic:
930934
raise TypeError("Class %r cannot be used with class "
931935
"or instance checks" % cls)
932-
if (cls.__origin__ is not None and
933-
sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']):
936+
if (
937+
cls.__origin__ is not None and
938+
sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']
939+
):
934940
raise TypeError("Parameterized generics cannot be used with class "
935941
"or instance checks")
936942

@@ -1057,9 +1063,12 @@ def __new__(cls, name, bases, namespace,
10571063
# This allows unparameterized generic collections to be used
10581064
# with issubclass() and isinstance() in the same way as their
10591065
# collections.abc counterparts (e.g., isinstance([], Iterable)).
1060-
if ('__subclasshook__' not in namespace and extra # allow overriding
1061-
or hasattr(self.__subclasshook__, '__name__') and
1062-
self.__subclasshook__.__name__ == '__extrahook__'):
1066+
if (
1067+
# allow overriding
1068+
'__subclasshook__' not in namespace and extra or
1069+
hasattr(self.__subclasshook__, '__name__') and
1070+
self.__subclasshook__.__name__ == '__extrahook__'
1071+
):
10631072
self.__subclasshook__ = _make_subclasshook(self)
10641073

10651074
if origin and hasattr(origin, '__qualname__'): # Fix for Python 3.2.

src/typing.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,17 @@ def _type_check(arg, msg):
355355
return type(None)
356356
if isinstance(arg, str):
357357
arg = _ForwardRef(arg)
358-
if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or
359-
not isinstance(arg, (type, _TypingBase)) and not callable(arg)):
358+
if (
359+
isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or
360+
not isinstance(arg, (type, _TypingBase)) and not callable(arg)
361+
):
360362
raise TypeError(msg + " Got %.100r." % (arg,))
361363
# Bare Union etc. are not valid as type arguments
362-
if (type(arg).__name__ in ('_Union', '_Optional')
363-
and not getattr(arg, '__origin__', None)
364-
or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)):
364+
if (
365+
type(arg).__name__ in ('_Union', '_Optional') and
366+
not getattr(arg, '__origin__', None) or
367+
isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)
368+
):
365369
raise TypeError("Plain %s is not valid as type argument" % arg)
366370
return arg
367371

@@ -850,8 +854,10 @@ def _valid_for_check(cls):
850854
if cls is Generic:
851855
raise TypeError("Class %r cannot be used with class "
852856
"or instance checks" % cls)
853-
if (cls.__origin__ is not None and
854-
sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']):
857+
if (
858+
cls.__origin__ is not None and
859+
sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']
860+
):
855861
raise TypeError("Parameterized generics cannot be used with class "
856862
"or instance checks")
857863

@@ -987,9 +993,12 @@ def __new__(cls, name, bases, namespace,
987993
# This allows unparameterized generic collections to be used
988994
# with issubclass() and isinstance() in the same way as their
989995
# collections.abc counterparts (e.g., isinstance([], Iterable)).
990-
if ('__subclasshook__' not in namespace and extra # allow overriding
991-
or hasattr(self.__subclasshook__, '__name__') and
992-
self.__subclasshook__.__name__ == '__extrahook__'):
996+
if (
997+
# allow overriding
998+
'__subclasshook__' not in namespace and extra or
999+
hasattr(self.__subclasshook__, '__name__') and
1000+
self.__subclasshook__.__name__ == '__extrahook__'
1001+
):
9931002
self.__subclasshook__ = _make_subclasshook(self)
9941003
if isinstance(extra, abc.ABCMeta):
9951004
self._abc_registry = extra._abc_registry
@@ -1443,10 +1452,12 @@ def get_type_hints(obj, globalns=None, localns=None):
14431452
hints = getattr(obj, '__annotations__', None)
14441453
if hints is None:
14451454
# Return empty annotations for something that _could_ have them.
1446-
if (isinstance(obj, types.FunctionType) or
1455+
if (
1456+
isinstance(obj, types.FunctionType) or
14471457
isinstance(obj, types.BuiltinFunctionType) or
14481458
isinstance(obj, types.MethodType) or
1449-
isinstance(obj, types.ModuleType)):
1459+
isinstance(obj, types.ModuleType)
1460+
):
14501461
return {}
14511462
else:
14521463
raise TypeError('{!r} is not a module, class, method, '

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ changedir = python2
1313
builtins = basestring, unicode
1414
ignore =
1515
# temporary ignores until we sort it out
16-
E129,
1716
E501,
18-
W503,
1917
# irrelevant plugins
2018
B3,
2119
DW12

0 commit comments

Comments
 (0)