Skip to content

Commit bee103b

Browse files
committed
Fix incorrect method type map resolution order
1 parent dd1366f commit bee103b

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

mypy_boto3_builder/type_maps/method_type_map.py

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,41 +98,6 @@
9898
}
9999

100100

101-
def _get_from_method_map(
102-
method_name: str,
103-
argument_name: str,
104-
method_type_map: MethodTypeMap,
105-
) -> FakeAnnotation | None:
106-
if ALL in method_type_map:
107-
operation_type_map = method_type_map[ALL]
108-
if argument_name in operation_type_map:
109-
return operation_type_map[argument_name]
110-
111-
if method_name in method_type_map:
112-
operation_type_map = method_type_map[method_name]
113-
if argument_name in operation_type_map:
114-
return operation_type_map[argument_name]
115-
116-
return None
117-
118-
119-
def _get_from_class_map(
120-
class_name: str,
121-
method_name: str,
122-
argument_name: str,
123-
class_type_map: ClassTypeMap,
124-
) -> FakeAnnotation | None:
125-
if class_name in class_type_map:
126-
result = _get_from_method_map(method_name, argument_name, class_type_map[class_name])
127-
if result:
128-
return result
129-
if ALL in class_type_map:
130-
result = _get_from_method_map(method_name, argument_name, class_type_map[ALL])
131-
if result:
132-
return result
133-
return None
134-
135-
136101
def _get_from_service_map(
137102
service_name: ServiceName,
138103
class_name: str,
@@ -143,12 +108,25 @@ def _get_from_service_map(
143108
if service_name not in service_type_map:
144109
return None
145110

146-
return _get_from_class_map(
147-
class_name,
148-
method_name,
149-
argument_name,
150-
service_type_map[service_name],
111+
checks = (
112+
(class_name, method_name, argument_name),
113+
(class_name, ALL, argument_name),
114+
(ALL, method_name, argument_name),
115+
(ALL, ALL, argument_name),
151116
)
117+
class_type_map = service_type_map[service_name]
118+
119+
for class_name, method_name, argument_name in checks:
120+
if class_name not in class_type_map:
121+
continue
122+
123+
method_type_map = class_type_map[class_name]
124+
125+
if method_name not in method_type_map:
126+
continue
127+
128+
operation_type_map = method_type_map[method_name]
129+
return operation_type_map.get(argument_name)
152130

153131

154132
def get_method_type_stub(

tests/type_maps/test_method_type_map.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ def test_get_method_type_stub(self) -> None:
1515
get_method_type_stub(ServiceNameCatalog.logs, "Client", "copy_object", "Unknown")
1616
is None
1717
)
18+
assert get_method_type_stub(
19+
ServiceNameCatalog.sqs, "SomeResource", "receive_messages", "AttributeNames"
20+
)
21+
assert (
22+
get_method_type_stub(
23+
ServiceNameCatalog.sqs, "SomeResource", "receive_messages", "Attribute"
24+
)
25+
is None
26+
)
1827

1928
def test_get_default_value_stub(self) -> None:
2029
assert get_default_value_stub(ServiceNameCatalog.glacier, "Client", "*", "accountId")

0 commit comments

Comments
 (0)