diff --git a/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md b/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md new file mode 100644 index 00000000000..49c3d6012e0 --- /dev/null +++ b/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Revert wrong code to avoid overwrite customized code when generation-subdir is set \ No newline at end of file diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index a95b1fd2f27..37657b08b29 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -183,8 +183,10 @@ def serialize(self) -> None: # When generation-subdir is configured, generated code goes into a subdirectory # (e.g., _generated/). We also need an __init__.py in the parent namespace dir # so that the package is discoverable by find_packages() / pip install. - if self.code_model.options.get("generation-subdir"): - root_dir = self.code_model.get_root_dir() + root_dir = self.code_model.get_root_dir() + if self.code_model.options.get("generation-subdir") and not self.read_file( + root_dir / Path("__init__.py") + ): self.write_file( root_dir / Path("__init__.py"), general_serializer.serialize_pkgutil_init_file(),