Skip to content
Draft
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: fix
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Keep original client name for backcompat reasons when the name is only padded for tsp generations
4 changes: 2 additions & 2 deletions packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "~0.20.3",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTU4Mzk0Ni9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "~4.19.1"
Expand All @@ -47,4 +47,4 @@
"requirements.txt",
"generator/"
]
}
}
4 changes: 2 additions & 2 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
"tsx": "~4.19.1",
"@typespec/http-client-python": "~0.20.3",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTU4Mzk0Ni9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.20.3.tgz",
"fs-extra": "~11.2.0"
},
"devDependencies": {
Expand Down Expand Up @@ -103,4 +103,4 @@
"chalk": "5.3.0",
"@types/fs-extra": "11.0.4"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
if not rf._rest_name_input:
rf._rest_name_input = attr
cls._attr_to_rest_field: dict[str, _RestField] = dict(attr_to_rest_field.items())
cls._backcompat_attr_to_rest_field: dict[str, _RestField] = {
Model._get_backcompat_attribute_name(cls._attr_to_rest_field, attr): rf
for attr, rf in cls._attr_to_rest_field.items()
}
cls._calculated.add(f"{cls.__module__}.{cls.__qualname__}")

return super().__new__(cls)
Expand All @@ -647,6 +651,16 @@ def __init_subclass__(cls, discriminator: typing.Optional[str] = None) -> None:
if hasattr(base, "__mapping__"):
base.__mapping__[discriminator or cls.__name__] = cls # type: ignore

@classmethod
def _get_backcompat_attribute_name(cls, attr_to_rest_field: dict[str, "_RestField"], attr_name: str) -> str:
rest_field_obj = attr_to_rest_field.get(attr_name) # pylint: disable=protected-access
if rest_field_obj is None:
return attr_name
original_tsp_name = getattr(rest_field_obj, "_original_tsp_name", None) # pylint: disable=protected-access
if original_tsp_name:
return original_tsp_name
return attr_name

@classmethod
def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField"]:
for v in cls.__dict__.values():
Expand Down Expand Up @@ -972,6 +986,7 @@ def _failsafe_deserialize_xml(
return None


# pylint: disable=too-many-instance-attributes
class _RestField:
def __init__(
self,
Expand All @@ -984,6 +999,7 @@ def __init__(
format: typing.Optional[str] = None,
is_multipart_file_input: bool = False,
xml: typing.Optional[dict[str, typing.Any]] = None,
original_tsp_name: typing.Optional[str] = None,
):
self._type = type
self._rest_name_input = name
Expand All @@ -995,6 +1011,7 @@ def __init__(
self._format = format
self._is_multipart_file_input = is_multipart_file_input
self._xml = xml if xml is not None else {}
self._original_tsp_name = original_tsp_name

@property
def _class_type(self) -> typing.Any:
Expand Down Expand Up @@ -1046,6 +1063,7 @@ def rest_field(
format: typing.Optional[str] = None,
is_multipart_file_input: bool = False,
xml: typing.Optional[dict[str, typing.Any]] = None,
original_tsp_name: typing.Optional[str] = None,
) -> typing.Any:
return _RestField(
name=name,
Expand All @@ -1055,6 +1073,7 @@ def rest_field(
format=format,
is_multipart_file_input=is_multipart_file_input,
xml=xml,
original_tsp_name=original_tsp_name,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ModelWithArrayOfModel(_Model):
name="items",
visibility=["read", "create", "update", "delete", "query"],
xml={"attribute": False, "itemsName": "SimpleModel", "name": "items", "text": False, "unwrapped": False},
original_tsp_name="items",
)
"""Required."""

Expand Down Expand Up @@ -142,6 +143,7 @@ class ModelWithEmptyArray(_Model):
name="items",
visibility=["read", "create", "update", "delete", "query"],
xml={"attribute": False, "itemsName": "SimpleModel", "name": "items", "text": False, "unwrapped": False},
original_tsp_name="items",
)
"""Required."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
if not rf._rest_name_input:
rf._rest_name_input = attr
cls._attr_to_rest_field: dict[str, _RestField] = dict(attr_to_rest_field.items())
cls._backcompat_attr_to_rest_field: dict[str, _RestField] = {
Model._get_backcompat_attribute_name(cls._attr_to_rest_field, attr): rf
for attr, rf in cls._attr_to_rest_field.items()
}
cls._calculated.add(f"{cls.__module__}.{cls.__qualname__}")

return super().__new__(cls)
Expand All @@ -641,6 +645,16 @@ def __init_subclass__(cls, discriminator: typing.Optional[str] = None) -> None:
if hasattr(base, "__mapping__"):
base.__mapping__[discriminator or cls.__name__] = cls # type: ignore

@classmethod
def _get_backcompat_attribute_name(cls, attr_to_rest_field: dict[str, "_RestField"], attr_name: str) -> str:
rest_field_obj = attr_to_rest_field.get(attr_name) # pylint: disable=protected-access
if rest_field_obj is None:
return attr_name
original_tsp_name = getattr(rest_field_obj, "_original_tsp_name", None) # pylint: disable=protected-access
if original_tsp_name:
return original_tsp_name
return attr_name

@classmethod
def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField"]:
for v in cls.__dict__.values():
Expand Down Expand Up @@ -966,6 +980,7 @@ def _failsafe_deserialize_xml(
return None


# pylint: disable=too-many-instance-attributes
class _RestField:
def __init__(
self,
Expand All @@ -978,6 +993,7 @@ def __init__(
format: typing.Optional[str] = None,
is_multipart_file_input: bool = False,
xml: typing.Optional[dict[str, typing.Any]] = None,
original_tsp_name: typing.Optional[str] = None,
):
self._type = type
self._rest_name_input = name
Expand All @@ -989,6 +1005,7 @@ def __init__(
self._format = format
self._is_multipart_file_input = is_multipart_file_input
self._xml = xml if xml is not None else {}
self._original_tsp_name = original_tsp_name

@property
def _class_type(self) -> typing.Any:
Expand Down Expand Up @@ -1040,6 +1057,7 @@ def rest_field(
format: typing.Optional[str] = None,
is_multipart_file_input: bool = False,
xml: typing.Optional[dict[str, typing.Any]] = None,
original_tsp_name: typing.Optional[str] = None,
) -> typing.Any:
return _RestField(
name=name,
Expand All @@ -1049,6 +1067,7 @@ def rest_field(
format=format,
is_multipart_file_input=is_multipart_file_input,
xml=xml,
original_tsp_name=original_tsp_name,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ModelWithArrayOfModel(_Model):
name="items",
visibility=["read", "create", "update", "delete", "query"],
xml={"attribute": False, "itemsName": "SimpleModel", "name": "items", "text": False, "unwrapped": False},
original_tsp_name="items",
)
"""Required."""

Expand Down Expand Up @@ -136,6 +137,7 @@ class ModelWithEmptyArray(_Model):
name="items",
visibility=["read", "create", "update", "delete", "query"],
xml={"attribute": False, "itemsName": "SimpleModel", "name": "items", "text": False, "unwrapped": False},
original_tsp_name="items",
)
"""Required."""

Expand Down
15 changes: 8 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading