From b6195d4e77e1309b4b4ecf77508a9ad65b007fcc Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 5 Nov 2016 22:11:52 +0100 Subject: [PATCH] Fix handling of typing.Union with newer Python 3.5 versions --- qutebrowser/commands/command.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 5d98c9166..a2bc3b50d 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -427,9 +427,16 @@ class Command: if isinstance(typ, tuple): raise TypeError("{}: Legacy tuple type annotation!".format( self.name)) - elif issubclass(typ, typing.Union): + elif type(typ) is type(typing.Union): # flake8: disable=E721 # 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: types.append(type(param.default)) choices = self.get_arg_info(param).choices