Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-python"
---

Fix extensible enum member names incorrectly getting an `Enum` suffix when the member name matched a Python reserved word (e.g. `ANDEnum` → `AND`, `CLASSEnum` → `CLASS`).
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Add mock API test coverage for extensible enum with special word member names in special-words spec.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# --------------------------------------------------------------------------
"""The preprocessing autorest plugin."""

import copy
from typing import Callable, Any, Optional

Expand Down Expand Up @@ -264,7 +265,7 @@ def update_types(self, yaml_data: list[dict[str, Any]]) -> None:
property["clientName"].lower(), PadType.PROPERTY, property
)
add_redefined_builtin_info(property["clientName"], property)
if type.get("name"):
if type.get("name") and type["type"] != "enumvalue":
pad_type = PadType.MODEL if type["type"] == "model" else PadType.ENUM_CLASS
name = self.pad_reserved_words(type["name"], pad_type, type)
type["name"] = name[0].upper() + name[1:]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from specialwords.aio import SpecialWordsClient
from specialwords import models
from specialwords.extensiblestrings import models as extensible_strings_models


@pytest.fixture
Expand Down Expand Up @@ -63,3 +64,9 @@ async def test_model_properties_dict_methods(client: SpecialWordsClient):
@pytest.mark.asyncio
async def test_model_properties_with_list(client: SpecialWordsClient):
await client.model_properties.with_list(models.ModelWithList(list="ok"))


@pytest.mark.asyncio
async def test_extensible_strings(client: SpecialWordsClient):
for enum_value in extensible_strings_models.ExtensibleString:
assert enum_value == await client.extensible_strings.put_extensible_string_value(body=enum_value)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------
import pytest
from specialwords import SpecialWordsClient, models
from specialwords.extensiblestrings import models as extensible_strings_models


@pytest.fixture
Expand Down Expand Up @@ -56,3 +57,8 @@ def test_model_properties_dict_methods(client: SpecialWordsClient):

def test_model_properties_with_list(client: SpecialWordsClient):
client.model_properties.with_list(models.ModelWithList(list="ok"))


def test_extensible_strings(client: SpecialWordsClient):
for enum_value in extensible_strings_models.ExtensibleString:
assert enum_value == client.extensible_strings.put_extensible_string_value(body=enum_value)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from specialwords.aio import SpecialWordsClient
from specialwords.models import models
from specialwords.modelproperties import models as model_properties_models
from specialwords.extensiblestrings import models as extensible_strings_models


@pytest.fixture
Expand Down Expand Up @@ -64,3 +65,9 @@ async def test_model_properties_dict_methods(client: SpecialWordsClient):
@pytest.mark.asyncio
async def test_model_properties_with_list(client: SpecialWordsClient):
await client.model_properties.with_list(model_properties_models.ModelWithList(list="ok"))


@pytest.mark.asyncio
async def test_extensible_strings(client: SpecialWordsClient):
for enum_value in extensible_strings_models.ExtensibleString:
assert enum_value == await client.extensible_strings.put_extensible_string_value(body=enum_value)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from specialwords import SpecialWordsClient
from specialwords.models import models
from specialwords.modelproperties import models as model_properties_models
from specialwords.extensiblestrings import models as extensible_strings_models


@pytest.fixture
Expand Down Expand Up @@ -58,3 +59,8 @@ def test_model_properties_dict_methods(client: SpecialWordsClient):

def test_model_properties_with_list(client: SpecialWordsClient):
client.model_properties.with_list(model_properties_models.ModelWithList(list="ok"))


def test_extensible_strings(client: SpecialWordsClient):
for enum_value in extensible_strings_models.ExtensibleString:
assert enum_value == client.extensible_strings.put_extensible_string_value(body=enum_value)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# --------------------------------------------------------------------------
from enum import Enum, EnumMeta
from specialwords.extensiblestrings import models as extensible_strings_models


class _CaseInsensitiveEnumMeta(EnumMeta):
Expand Down Expand Up @@ -50,3 +51,39 @@ def test_find():
def test_join():
assert EnumsWithCallableNames.JOIN == "join"
assert callable(EnumsWithCallableNames.join)


def test_extensible_strings_enum_with_special_words():
assert extensible_strings_models.ExtensibleString.AND == "and"
assert extensible_strings_models.ExtensibleString.AS == "as"
assert extensible_strings_models.ExtensibleString.ASSERT == "assert"
assert extensible_strings_models.ExtensibleString.ASYNC == "async"
assert extensible_strings_models.ExtensibleString.AWAIT == "await"
assert extensible_strings_models.ExtensibleString.BREAK == "break"
assert extensible_strings_models.ExtensibleString.CLASS == "class"
assert extensible_strings_models.ExtensibleString.CONSTRUCTOR == "constructor"
assert extensible_strings_models.ExtensibleString.CONTINUE == "continue"
assert extensible_strings_models.ExtensibleString.DEF == "def"
assert extensible_strings_models.ExtensibleString.DEL == "del"
assert extensible_strings_models.ExtensibleString.ELIF == "elif"
assert extensible_strings_models.ExtensibleString.ELSE == "else"
assert extensible_strings_models.ExtensibleString.EXCEPT == "except"
assert extensible_strings_models.ExtensibleString.EXEC == "exec"
assert extensible_strings_models.ExtensibleString.FINALLY == "finally"
assert extensible_strings_models.ExtensibleString.FOR == "for"
assert extensible_strings_models.ExtensibleString.FROM == "from"
assert extensible_strings_models.ExtensibleString.GLOBAL == "global"
assert extensible_strings_models.ExtensibleString.IF == "if"
assert extensible_strings_models.ExtensibleString.IMPORT == "import"
assert extensible_strings_models.ExtensibleString.IN == "in"
assert extensible_strings_models.ExtensibleString.IS == "is"
assert extensible_strings_models.ExtensibleString.LAMBDA == "lambda"
assert extensible_strings_models.ExtensibleString.NOT == "not"
assert extensible_strings_models.ExtensibleString.OR == "or"
assert extensible_strings_models.ExtensibleString.PASS == "pass"
assert extensible_strings_models.ExtensibleString.RAISE == "raise"
assert extensible_strings_models.ExtensibleString.RETURN == "return"
assert extensible_strings_models.ExtensibleString.TRY == "try"
assert extensible_strings_models.ExtensibleString.WHILE == "while"
assert extensible_strings_models.ExtensibleString.WITH == "with"
assert extensible_strings_models.ExtensibleString.YIELD == "yield"
22 changes: 11 additions & 11 deletions packages/http-client-python/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@typespec/sse": "~0.79.0",
"@typespec/streams": "~0.79.0",
"@typespec/xml": "~0.79.0",
"@typespec/http-specs": "0.1.0-alpha.33-dev.2",
"@typespec/http-specs": "0.1.0-alpha.33-dev.5",
"@types/js-yaml": "~4.0.5",
"@types/node": "~25.0.2",
"@types/semver": "7.5.8",
Expand Down
Loading