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

Assign node to applicator before reapply can happen #232

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

HalfWhitt
Copy link
Contributor

@HalfWhitt HalfWhitt commented Nov 5, 2024

Oops. Working on beeware/toga#2937 led me to notice I'd missed an important part of the necessary order here. The applicator should know what its node is before the applicator is assigned to the style, so it will have the reference when reapplying happens.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

A couple of comments about needed comments inline, plus a possible edge case that probably isn't the end of the world, but would be worth clarifying.

if applicator:
applicator.node = self

self._applicator = applicator
self.style._applicator = applicator
Copy link
Member

Choose a reason for hiding this comment

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

Since we're thinking about the edge cases: if there's an existing applicator, should we be clearing the node reference on that applicator? I don't think it will make any difference in practice right now, but for symmetry, it couldn't hurt.

Copy link
Member

Choose a reason for hiding this comment

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

Also - given this bit us, it would be worth adding a quick comment explaining why the order is significant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't thought of that, that's a good point.

@@ -371,3 +383,12 @@ def test_apply_before_node_is_ready():

with pytest.warns(RuntimeWarning):
Node(style=style, applicator=applicator)


def test_applicator_has_node_reference():
Copy link
Member

Choose a reason for hiding this comment

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

It took me a moment to work out why this test was different to the last assertion in test_apply_before_node_is_ready, except that it wasn't actually asserting that the warning was raised. A comment on the fact that AttributeTestStyle asserts that it is re-applied would be helpful.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

👍 Looks good - thanks for the fix!

@freakboy3742 freakboy3742 merged commit bae5b49 into beeware:main Nov 6, 2024
9 checks passed
@HalfWhitt HalfWhitt deleted the applicator_node_order branch November 6, 2024 01:42
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