Fix handling of typing.Union with newer Python 3.5 versions

This commit is contained in:
Florian Bruhin 2016-11-05 22:11:52 +01:00
parent 18e5334905
commit b6195d4e77

View File

@ -427,9 +427,16 @@ class Command:
if isinstance(typ, tuple): if isinstance(typ, tuple):
raise TypeError("{}: Legacy tuple type annotation!".format( raise TypeError("{}: Legacy tuple type annotation!".format(
self.name)) self.name))
elif issubclass(typ, typing.Union): elif type(typ) is type(typing.Union): # flake8: disable=E721
# this is... slightly evil, I know # this is... slightly evil, I know
types = list(typ.__union_params__) # pylint: disable=no-member # We also can't use isinstance here because typing.Union doesn't
# support that.
# pylint: disable=no-member,useless-suppression
try:
types = list(typ.__union_params__)
except AttributeError:
types = list(typ.__args__)
# pylint: enable=no-member,useless-suppression
if param.default is not inspect.Parameter.empty: if param.default is not inspect.Parameter.empty:
types.append(type(param.default)) types.append(type(param.default))
choices = self.get_arg_info(param).choices choices = self.get_arg_info(param).choices