aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-installer/anaconda/files/0001-Make-pyanaconda.dbus.typing-work-with-Python-3.7-159.patch
blob: 8cf6219f37563fc62c9e53f02eb5d69c5f7c023a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From cab126462e1f0de4487fd4bf1202a34590fceb90 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Fri, 6 Jul 2018 15:04:39 -0700
Subject: [PATCH] Make pyanaconda.dbus.typing work with Python 3.7 (#1598574)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As reported in RHBZ#1598574, the internals of typing changed in
Python 3.7 such that it's no longer so simple to find the 'base'
type of a type hint (it's not just its `__origin__` any more).
There doesn't appear to be any particularly great fix for this,
but this suggestion from Miro Hrončok seems as good as any other
option we have for now. This should work with both 3.6 and 3.7.

Based on solution from Adam Williamson <awilliam@redhat.com>.

Upstream-Status: Backport
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 pyanaconda/dbus/typing.py | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/pyanaconda/dbus/typing.py b/pyanaconda/dbus/typing.py
index ea8a299..0f771e6 100644
--- a/pyanaconda/dbus/typing.py
+++ b/pyanaconda/dbus/typing.py
@@ -149,24 +149,39 @@ class DBusType(object):
     @staticmethod
     def _is_container_type(type_hint):
         """Is it a container type?"""
-        # Try to get the "base" type of the container type.
+        return DBusType._get_container_base_type(type_hint) is not None
+
+    @staticmethod
+    def _get_container_base_type(type_hint):
+        """Return a container base type."""
+        # Try to get the "origin" of the hint.
         origin = getattr(type_hint, "__origin__", None)
-        return origin in DBusType._container_type_mapping
+
+        if not origin:
+            return None
+
+        # Return the container base type of the "origin" or None.
+        # See: https://bugzilla.redhat.com/show_bug.cgi?id=1598574
+        for basetype in DBusType._container_type_mapping:
+            if issubclass(origin, basetype):
+                return basetype
+
+        return None
 
     @staticmethod
     def _get_container_type(type_hint):
         """Return a container type."""
-        # Get the "base" type of the container.
-        origin = type_hint.__origin__
+        basetype = DBusType._get_container_base_type(type_hint)
+
         # Get the arguments of the container.
         args = type_hint.__args__
 
         # Check the typing.
-        if origin == Dict:
+        if basetype == Dict:
             DBusType._check_if_valid_dictionary(type_hint)
 
         # Generate string.
-        container = DBusType._container_type_mapping[origin]
+        container = DBusType._container_type_mapping[basetype]
         items = [DBusType.get_dbus_representation(arg) for arg in args]
         return container % "".join(items)
 
-- 
2.7.4