Skip to content

Commit

Permalink
[python] always generate models with base init (#5517)
Browse files Browse the repository at this point in the history
We have semi-complicated logic right now to determine whether we want to
generate inits on our DPG models. This is to clean up the logic

See
[this](https://teams.microsoft.com/l/message/19:b97d98e6d22c41e0970a1150b484d935@thread.skype/1736216580225?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=3e17dcb0-4257-4a30-b843-77f47f1d4121&parentMessageId=1736216580225&teamName=Azure%20SDK&channelName=Language%20-%20Python&createdTime=1736216580225)
teams convo for more context.

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
  • Loading branch information
iscai-msft and iscai-msft authored Jan 9, 2025
1 parent a7e61a0 commit e873e63
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,4 @@ BenchmarkDotnet.Artifacts/
packages/http-client-python/generator/test/**/generated/
packages/http-client-python/generator/test/**/cadl-ranch-coverage.json
!packages/http-client-python/package-lock.json
micropip.lock
6 changes: 6 additions & 0 deletions packages/http-client-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log - @typespec/http-client-python

## 0.6.1

### Bug Fixes

- Generate `__init__` for all DPG models to ensure stability

## 0.6.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def properties_to_pass_to_super(model: ModelType) -> str:
def initialize_properties(self, model: ModelType) -> List[str]: ...

def need_init(self, model: ModelType) -> bool:
return (not model.internal) and bool(self.init_line(model) or model.discriminator)
return bool(self.init_line(model) or model.discriminator)

def pylint_disable_items(self, model: ModelType) -> List[str]:
if model.flattened_property or self.initialize_properties(model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def test_operation(client: AccessClient):
@pytest.mark.asyncio
async def test_discriminator(client: AccessClient):
result = await client.relative_model_in_operation._discriminator(kind="real")
assert result == models._models.RealModel(name="Madge", kind="real")
assert result == models._models.RealModel(name="Madge")

with pytest.raises(ImportError):
from specs.azure.clientgenerator.core.access.models import RealModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_operation(client: AccessClient):

def test_discriminator(client: AccessClient):
result = client.relative_model_in_operation._discriminator(kind="real")
assert result == models._models.RealModel(name="Madge", kind="real")
assert result == models._models.RealModel(name="Madge")

with pytest.raises(ImportError):
from specs.azure.clientgenerator.core.access.models import RealModel
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "@typespec/http-client-python",
"version": "0.6.0",
"version": "0.6.1",
"author": "Microsoft Corporation",
"description": "TypeSpec emitter for Python SDKs",
"homepage": "https://typespec.io",
Expand Down

0 comments on commit e873e63

Please sign in to comment.