Skip to content

fix: set a proper default value for non-nullable python fields#6489

Closed
ntauth wants to merge 1 commit intomicrosoft:mainfrom
ntauth:fix/issue-6350-mutable-default-value-in-non-nullable-python-fields
Closed

fix: set a proper default value for non-nullable python fields#6489
ntauth wants to merge 1 commit intomicrosoft:mainfrom
ntauth:fix/issue-6350-mutable-default-value-in-non-nullable-python-fields

Conversation

@ntauth
Copy link

@ntauth ntauth commented Apr 22, 2025

Fixes #6350

@ntauth
Copy link
Author

ntauth commented Apr 22, 2025

@ntauth please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Hoshii AG"

conventions.WriteInLineDescription(codeElement, writer);
var isNonNullableCollection = !codeElement.Type.IsNullable && codeElement.Type.CollectionKind != CodeTypeBase.CodeTypeCollectionKind.None;
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)}{codeElement.NamePrefix}{codeElement.Name}: {(codeElement.Type.IsNullable ? "Optional[" : string.Empty)}{returnType}{(codeElement.Type.IsNullable ? "]" : string.Empty)} {(isNonNullableCollection ? "= []" : "= None")}");
var defaultFactoryType = codeElement.Type.CollectionKind.IsArray() ? "list" : "dict";
Copy link
Author

@ntauth ntauth Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added "dict" as the other option because of the Complex type of CollectionKind. I assume Complex == object? That should never happen irl though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None = single value,
Array = Array,
Complex = List or equivalent on the platform.

With that information in mind, can you please update the code?

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, can you please add a changelog entry (unreleased, changed)

conventions.WriteInLineDescription(codeElement, writer);
var isNonNullableCollection = !codeElement.Type.IsNullable && codeElement.Type.CollectionKind != CodeTypeBase.CodeTypeCollectionKind.None;
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)}{codeElement.NamePrefix}{codeElement.Name}: {(codeElement.Type.IsNullable ? "Optional[" : string.Empty)}{returnType}{(codeElement.Type.IsNullable ? "]" : string.Empty)} {(isNonNullableCollection ? "= []" : "= None")}");
var defaultFactoryType = codeElement.Type.CollectionKind.IsArray() ? "list" : "dict";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None = single value,
Array = Array,
Complex = List or equivalent on the platform.

With that information in mind, can you please update the code?

@baywet
Copy link
Member

baywet commented Jun 9, 2025

@ntauth gentle reminder on this :)

@ntauth
Copy link
Author

ntauth commented Jun 11, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array of item /w enum creates invalid dataclass in python

2 participants