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

Improve warning message when a field name shadows a field in a parent model #9105

Merged
merged 3 commits into from Mar 26, 2024

Conversation

chan-vince
Copy link
Contributor

@chan-vince chan-vince commented Mar 26, 2024

Change Summary

Added in #7193, a helpful warning message is displayed when a subclass contains a field with the same name as the parent class.

If you have many models that inherit from a parent class, it would be helpful to be able to see in the warning message which child model contains the duplicate field name - not just the parent class.

So I've simply tweaked the warning message text to allow the user to easily see which model they should inspect.

Before:

UserWarning: Field name "foo" shadows an attribute in parent "ParentModel";

After:

UserWarning: Field name "foo" in "ChildModel" shadows an attribute in parent "ParentModel"

I think this is clearer for cases where you have tens or hundreds of ChildModels.

I also removed the semi-colon because I'm not sure why it's there, but happy to put that back, I may have missed a convention or other warning message or code style rule.

Related issue number

None

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @Kludex

@chan-vince
Copy link
Contributor Author

please review

Copy link

codspeed-hq bot commented Mar 26, 2024

CodSpeed Performance Report

Merging #9105 will not alter performance

Comparing chan-vince:improve-user-warning-message (75a6f02) with main (af3d335)

Summary

✅ 10 untouched benchmarks

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Mar 26, 2024
Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Great work, thank you!

@sydney-runkle sydney-runkle merged commit e3b4633 into pydantic:main Mar 26, 2024
53 of 54 checks passed
@chan-vince chan-vince deleted the improve-user-warning-message branch March 26, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants