Skip to content

Commit 228d085

Browse files
iscai-msftiscai-msft
andauthored
[http-client-python] import mixin operations from init file (#7992)
When we made mixin operations private, we updated all of our imports to import from the exact file it was generated in, instead of from the `operations` module. This makes patch changes to the mixin operation class via `operations/_patch.py` lose their effect, and was an unintended consequence. This PR fixes that, importing mixin operation classes from `operations/__init__.py` so patch changes still take effect --------- Co-authored-by: iscai-msft <isabellavcai@gmail.com>
1 parent 67dfa02 commit 228d085

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Import mixins from operations init file to get patch changes

packages/http-client-python/generator/pygen/codegen/models/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,11 @@ def imports(self, async_mode: bool, **kwargs) -> FileImport:
322322
)
323323
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
324324
for og in self.operation_groups:
325-
suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
326325
file_import.add_submodule_import(
327326
self.code_model.get_relative_import_path(
328327
serialize_namespace,
329328
self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
330-
)
331-
+ suffix,
329+
),
332330
og.class_name,
333331
ImportType.LOCAL,
334332
)

packages/http-client-python/generator/pygen/codegen/serializers/operations_init_serializer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
from ..models import CodeModel, OperationGroup
1010

1111

12+
def get_pylint_disable(code_model: CodeModel, og: OperationGroup) -> str:
13+
if og.is_mixin and not code_model.options["multiapi"]:
14+
return " # pylint: disable=unused-import"
15+
return ""
16+
17+
1218
class OperationsInitSerializer:
1319
def __init__(
1420
self,
@@ -27,9 +33,8 @@ def _get_filename(operation_group: OperationGroup) -> str:
2733
return "_operations" if self.code_model.options["combine-operation-files"] else operation_group.filename
2834

2935
return [
30-
f"from .{_get_filename(og)} import {og.class_name} # type: ignore"
36+
f"from .{_get_filename(og)} import {og.class_name} # type: ignore{get_pylint_disable(self.code_model, og)}"
3137
for og in self.operation_groups
32-
if not og.is_mixin or self.code_model.options["multiapi"]
3338
]
3439

3540
def serialize(self) -> str:

0 commit comments

Comments
 (0)