diff --git a/python2/typing.py b/python2/typing.py index 88382f14..ab196a17 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -328,13 +328,17 @@ def _type_check(arg, msg): return type(None) if isinstance(arg, basestring): arg = _ForwardRef(arg) - if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or - not isinstance(arg, (type, _TypingBase)) and not callable(arg)): + if ( + isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or + not isinstance(arg, (type, _TypingBase)) and not callable(arg) + ): raise TypeError(msg + " Got %.100r." % (arg,)) # Bare Union etc. are not valid as type arguments - if (type(arg).__name__ in ('_Union', '_Optional') - and not getattr(arg, '__origin__', None) - or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)): + if ( + type(arg).__name__ in ('_Union', '_Optional') and + not getattr(arg, '__origin__', None) or + isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol) + ): raise TypeError("Plain %s is not valid as type argument" % arg) return arg @@ -929,8 +933,10 @@ def _valid_for_check(cls): if cls is Generic: raise TypeError("Class %r cannot be used with class " "or instance checks" % cls) - if (cls.__origin__ is not None and - sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']): + if ( + cls.__origin__ is not None and + sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools'] + ): raise TypeError("Parameterized generics cannot be used with class " "or instance checks") @@ -1057,9 +1063,12 @@ def __new__(cls, name, bases, namespace, # This allows unparameterized generic collections to be used # with issubclass() and isinstance() in the same way as their # collections.abc counterparts (e.g., isinstance([], Iterable)). - if ('__subclasshook__' not in namespace and extra # allow overriding - or hasattr(self.__subclasshook__, '__name__') and - self.__subclasshook__.__name__ == '__extrahook__'): + if ( + # allow overriding + '__subclasshook__' not in namespace and extra or + hasattr(self.__subclasshook__, '__name__') and + self.__subclasshook__.__name__ == '__extrahook__' + ): self.__subclasshook__ = _make_subclasshook(self) if origin and hasattr(origin, '__qualname__'): # Fix for Python 3.2. diff --git a/src/typing.py b/src/typing.py index bfd7e94b..c5b58b1c 100644 --- a/src/typing.py +++ b/src/typing.py @@ -355,13 +355,17 @@ def _type_check(arg, msg): return type(None) if isinstance(arg, str): arg = _ForwardRef(arg) - if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or - not isinstance(arg, (type, _TypingBase)) and not callable(arg)): + if ( + isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or + not isinstance(arg, (type, _TypingBase)) and not callable(arg) + ): raise TypeError(msg + " Got %.100r." % (arg,)) # Bare Union etc. are not valid as type arguments - if (type(arg).__name__ in ('_Union', '_Optional') - and not getattr(arg, '__origin__', None) - or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)): + if ( + type(arg).__name__ in ('_Union', '_Optional') and + not getattr(arg, '__origin__', None) or + isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol) + ): raise TypeError("Plain %s is not valid as type argument" % arg) return arg @@ -850,8 +854,10 @@ def _valid_for_check(cls): if cls is Generic: raise TypeError("Class %r cannot be used with class " "or instance checks" % cls) - if (cls.__origin__ is not None and - sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']): + if ( + cls.__origin__ is not None and + sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools'] + ): raise TypeError("Parameterized generics cannot be used with class " "or instance checks") @@ -987,9 +993,12 @@ def __new__(cls, name, bases, namespace, # This allows unparameterized generic collections to be used # with issubclass() and isinstance() in the same way as their # collections.abc counterparts (e.g., isinstance([], Iterable)). - if ('__subclasshook__' not in namespace and extra # allow overriding - or hasattr(self.__subclasshook__, '__name__') and - self.__subclasshook__.__name__ == '__extrahook__'): + if ( + # allow overriding + '__subclasshook__' not in namespace and extra or + hasattr(self.__subclasshook__, '__name__') and + self.__subclasshook__.__name__ == '__extrahook__' + ): self.__subclasshook__ = _make_subclasshook(self) if isinstance(extra, abc.ABCMeta): self._abc_registry = extra._abc_registry @@ -1443,10 +1452,12 @@ def get_type_hints(obj, globalns=None, localns=None): hints = getattr(obj, '__annotations__', None) if hints is None: # Return empty annotations for something that _could_ have them. - if (isinstance(obj, types.FunctionType) or + if ( + isinstance(obj, types.FunctionType) or isinstance(obj, types.BuiltinFunctionType) or isinstance(obj, types.MethodType) or - isinstance(obj, types.ModuleType)): + isinstance(obj, types.ModuleType) + ): return {} else: raise TypeError('{!r} is not a module, class, method, ' diff --git a/tox.ini b/tox.ini index f4895cdb..c8c5aaae 100644 --- a/tox.ini +++ b/tox.ini @@ -13,9 +13,7 @@ changedir = python2 builtins = basestring, unicode ignore = # temporary ignores until we sort it out - E129, E501, - W503, # irrelevant plugins B3, DW12