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

Fix msgspec template to add field #1942

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ianbuss
Copy link

@ianbuss ianbuss commented May 1, 2024

With msgspec outputs, the order of generated fields sometimes results in invalid class definitions, with required and optional fields in the wrong order. Additionally, if using --snake-case-field, field aliases are not added.

This PR contains the following fixes:

  • The _has_field_assignment sort function is modified to sort optional fields last
  • The __str__ function for msgspec fields is updated to add an explicit None default for optional fields when no other default has been set.
  • The jinja template is modified to write out the field.field for annotated types.
  • Added a new unit test to and modified existing tests in test_main.py.

Fixes #1943
Fixes #1919
Fixes #1920

@ianbuss ianbuss force-pushed the retain-ordering-of-fields-with-snake-casing branch from 566fb56 to cf683e4 Compare May 9, 2024 19:23
Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@fcab9a4). Click here to learn what that means.

❗ Current head 566fb56 differs from pull request most recent head 0d802a4. Consider uploading reports for the commit 0d802a4 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1942   +/-   ##
=======================================
  Coverage        ?   98.90%           
=======================================
  Files           ?       37           
  Lines           ?     4182           
  Branches        ?      972           
=======================================
  Hits            ?     4136           
  Misses          ?       29           
  Partials        ?       17           
Flag Coverage Δ
unittests 98.56% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented May 9, 2024

CodSpeed Performance Report

Merging #1942 will not alter performance

Comparing ianbuss:retain-ordering-of-fields-with-snake-casing (566fb56) with main (fcab9a4)

Summary

✅ 29 untouched benchmarks

@ianbuss ianbuss changed the title Adjust sorting function in msgspec fields to account for snake casing Fix msgspec template to add field May 10, 2024
@ianbuss ianbuss marked this pull request as draft May 10, 2024 11:47
@ianbuss ianbuss marked this pull request as ready for review May 10, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant