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

core: Allowing overload of ClassVar from superclass #2690

Merged
merged 2 commits into from
Jun 6, 2024

Conversation

n-io
Copy link
Collaborator

@n-io n-io commented Jun 5, 2024

This is to enhance PR #2687, which allowed uppercase ClassVar fields on ops.

This PR adds support for the case that an uppercase ClassVar is defined (without a value) in a superclass and assigned a value in a subclass. This is confirmed by performing the same check as in the other PR.

Copy link

codecov bot commented Jun 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.70%. Comparing base (2782ac6) to head (d45e2e8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2690   +/-   ##
=======================================
  Coverage   89.69%   89.70%           
=======================================
  Files         366      366           
  Lines       47049    47071   +22     
  Branches     7139     7140    +1     
=======================================
+ Hits        42201    42223   +22     
  Misses       3745     3745           
  Partials     1103     1103           

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

Comment on lines 1475 to 1482
if field_name.isupper() and (
get_origin(annotations[field_name]) is ClassVar
or (
isinstance(annotations[field_name], str)
and annotations[field_name].startswith("ClassVar")
)
):
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seeing as we have this in two places now, could we factor this out to make it easier to see that the two checks are identical? And maybe also make this code denser again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That sounds very reasonable, have factored out the check as suggested.

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

Just a minor nit on factoring out the check. Otherwise LGTM, thanks for the core contribution!

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Very nice!

@n-io n-io merged commit a83b98b into main Jun 6, 2024
10 checks passed
@n-io n-io deleted the nicolai/allow-classvars-from-superclass branch June 6, 2024 11:50
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.

3 participants