Redundant isinstance checks generated for unions where every member is a model
#1486
AndersBennedsgaard
started this conversation in
Feature request
Replies: 1 comment
|
I submitted a PR at #1487. It's probably easier to look at that to see if it is something we need |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When a property is a union of schemas that are all object/model types (e.g.
oneOf: [ModelA, ModelB]), the generatedto_dict()method checks the type of the value withisinstancebefore converting it, even though every possible type is converted the exact same way (.to_dict()). The type check doesn't actually change anything, since every generated model class is converted identically.This makes the generated code harder to read than necessary, and trips up linters (e.g. ruff flags it when using the
SIMrules).Generated today:
Expected:
Note: This only applies when every member of the union is a model. Unions that mix models with primitives/enums must keep their existing per-member check, since those really do need different handling.
All reactions