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

api: remove parameters field from Trait #2940

Merged
merged 2 commits into from
Jul 29, 2024
Merged

Conversation

superlopuh
Copy link
Member

These make the API more complicated than it needs to be, since all traits are frozen dataclasses we can let the dataclass annotation do the heavy lifting for comparison and hashability.

@superlopuh superlopuh added the API Related to changes regarding API of constructs label Jul 25, 2024
@superlopuh superlopuh self-assigned this Jul 25, 2024
def get_trait(
cls, trait: type[OpTraitInvT], parameters: Any = None
) -> OpTraitInvT | None:
def get_trait(cls, trait: type[OpTraitInvT] | OpTraitInvT) -> OpTraitInvT | None:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a breaking change, but the fix is just a couple of backspaces to delete the comma and instantiate the class instead of passing the parameters separately

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.88%. Comparing base (38effb9) to head (101e555).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2940      +/-   ##
==========================================
- Coverage   89.88%   89.88%   -0.01%     
==========================================
  Files         408      408              
  Lines       50908    50916       +8     
  Branches     7880     7884       +4     
==========================================
+ Hits        45760    45767       +7     
- Misses       3908     3909       +1     
  Partials     1240     1240              

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

Copy link
Collaborator

@webmiche webmiche left a comment

Choose a reason for hiding this comment

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

LGTM in general.

I am not sure we want to remove parameters from traits. It feels to me like parameters are something that traits should have. Or at least, that the concept of a parametrized trait deserves its own class.
So, to me, this is fine in a technical sense, but it feels to me like what I understand as a trait and what the class implements is not quite the same anymore.

That's not a blocking comment though, I am fine with merging this.

Copy link
Collaborator

@n-io n-io left a comment

Choose a reason for hiding this comment

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

Merged main to resolve a conflict in csl_stencil, check if you're happy, lgmt.

@superlopuh
Copy link
Member Author

Thank you! To me the thing that makes this still have the property of "traits with parameters" is that frozen dataclasses have fields that you can inspect and reason about, so you still have this notion of a named introspectable structure, but without more infrastructure on our end.

@superlopuh superlopuh merged commit 41b3bf6 into main Jul 29, 2024
10 checks passed
@superlopuh superlopuh deleted the sasha/irdl/no-trait-params branch July 29, 2024 09:06
if not parameters:
raise ValueError("parameters must not be empty")
super().__init__(parameters)
def __init__(self, head_param: type[Operation], *tail_params: type[Operation]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not super() init?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no super init here that would set the op types property, as far as I understand


def __init__(self, head_param: type[Operation], *tail_params: type[Operation]):
super().__init__((head_param, *tail_params))
object.__setattr__(self, "op_types", (head_param, *tail_params))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to changes regarding API of constructs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants