Skip to content

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Aug 5, 2019

Change Summary

Modifies field ordering so that all annotated fields occur in the order included.

Note: non-annotated fields still come last; this is probably unavoidable.

This is a subtly breaking change, so, if desired, should probably be part of 1.0.

Related issue number

Related to #674 #483 #203 #716

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • HISTORY.rst has been updated
    • if this is the first change since a release, please add a new section
    • include the issue number or this pull request number #<number>
    • include your github username @<whomever>

@codecov
Copy link

codecov bot commented Aug 5, 2019

Codecov Report

Merging #715 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #715   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines        2710   2807   +97     
  Branches      532    578   +46     
=====================================
+ Hits         2710   2807   +97

@samuelcolvin samuelcolvin added this to the Version 1 milestone Aug 6, 2019
@samuelcolvin
Copy link
Member

please can you rebase and move the history change to changes/ as per #719.

@samuelcolvin
Copy link
Member

as per #716 I guess we should implement Config.require_annotations = True

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise looks good, plus Config.require_annotations = True

pydantic/main.py Outdated
name=var_name,
value=value,
annotation=annotations.get(var_name),
class_validators=vg.get_validators(var_name),
config=config,
)
new_fields_ordering = [k for k in annotations if k in new_fields] + [
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new_fields_ordering = [k for k in annotations if k in new_fields] + [
ordered_new_fields = [k for k in annotations if k in new_fields] + [

pydantic/main.py Outdated
new_fields_ordering = [k for k in annotations if k in new_fields] + [
k for k in new_fields if k not in annotations
]
for k in new_fields_ordering:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for k in new_fields_ordering:
fields.update(ordered_new_fields)

I think.

Copy link
Contributor Author

@dmontagu dmontagu Aug 8, 2019

Choose a reason for hiding this comment

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

new_fields_ordering only includes the keys, not the values; your modification above didn't change that, as far as I can tell. So ordered_new_fields is a List[str], not a Dict[str, Field].

I'm happy to rename, but I couldn't come up with a way to get ordered_new_fields to be a dict without making things ugly elsewhere. Let me know if you want me to try harder.

Copy link
Member

Choose a reason for hiding this comment

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

Humm, that's true sorry.

Rather than describe it all, i'll commit to your PR and you can change or remove it if it doesn't make sense.

Copy link
Member

Choose a reason for hiding this comment

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

take a look at d3b10e5, I think that's better than building the order wrong then rebuilding it right, but happy to change if I'm missing something.

@samuelcolvin
Copy link
Member

@dmontagu kind of unrelated, but nowhere better to discuss:

Could I have your email address? If you're not happy sharing it publicly, feel free to email s@muelcolvin.com.

@dmontagu
Copy link
Contributor Author

dmontagu commented Aug 9, 2019

@dmontagu kind of unrelated, but nowhere better to discuss:

Could I have your email address? If you're not happy sharing it publicly, feel free to email s@muelcolvin.com.

Sent you an email, let me know if you didn't get it.

@samuelcolvin
Copy link
Member

samuelcolvin commented Aug 12, 2019

@dmontagu are you happy with this? If so I guess it can be merged.

@dmontagu
Copy link
Contributor Author

@samuelcolvin I'm good with it, feel free to merge once the checks re-pass.

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.

2 participants