Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: typespec-python - discriminated polymorphic types as op parameters generated incorrectly #6135

Open
4 tasks done
johanste opened this issue Feb 25, 2025 · 1 comment
Labels
bug Something isn't working emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Comments

@johanste
Copy link
Contributor

johanste commented Feb 25, 2025

Describe the bug

We type base[] as list[base] in method parameters. That does not compute with polymorphic types.

Reproduction

@service()
namespace PolymorphicVariance;

@discriminator("kind")
model Pet {
  kind: string;
}

model Cat extends Pet {
  kind: "cat"
}

model Dog extends Pet {
  kind: "dog"
}

op cuddle(ingredients: Pet[]): void;

repro.py

cuddle([Dog(), Cat()])
$> pyright repro.py

Checklist

@johanste johanste added the bug Something isn't working label Feb 25, 2025
@johanste
Copy link
Contributor Author

johanste commented Feb 25, 2025

And to clarify, the parameter type needs to be a covariant ordered collection type (e.g. Iterable or - in theory - Sequence - but Sequence would impose to constraints on the input that we actually don't need) rather than an invariant type because an invariant type means that list can only contain the very specific type in the list.

@johanste johanste added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working emitter:client:python Issue for the Python client emitter: @typespec/http-client-python
Projects
None yet
Development

No branches or pull requests

1 participant