Skip to content

Commit 8d91b9c

Browse files
authored
Merge pull request #12959 [BEAM-10978] Fix bug with map type inference.
2 parents 167385b + 0a507a1 commit 8d91b9c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sdks/python/apache_beam/typehints/opcodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def build_map(state, arg):
269269
if sys.version_info <= (2, ) or arg == 0:
270270
state.stack.append(Dict[Union[()], Union[()]])
271271
else:
272-
state.stack[-arg:] = [
272+
state.stack[-2 * arg:] = [
273273
Dict[reduce(union, state.stack[-2 * arg::2], Union[()]),
274274
reduce(union, state.stack[-2 * arg + 1::2], Union[()])]
275275
]

sdks/python/apache_beam/typehints/trivial_inference_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def testBuildMap(self):
112112
v: {}, [int, float])
113113
self.assertReturnType(
114114
typehints.Dict[int, float], lambda k, v: {k: v}, [int, float])
115+
self.assertReturnType(
116+
typehints.Tuple[str, typehints.Dict[int, float]],
117+
lambda k,
118+
v: ('s', {
119+
k: v
120+
}), [int, float])
115121
self.assertReturnType(
116122
typehints.Dict[int, typehints.Union[float, str]],
117123
lambda k1,
@@ -128,6 +134,12 @@ def testBuildMap(self):
128134
b: {
129135
'a': a, 'b': b
130136
}, [int, float])
137+
self.assertReturnType(
138+
typehints.Tuple[int, typehints.Dict[str, typehints.Union[int, float]]],
139+
lambda a,
140+
b: (4, {
141+
'a': a, 'b': b
142+
}), [int, float])
131143

132144
def testNoneReturn(self):
133145
def func(a):

0 commit comments

Comments
 (0)