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

fix: the other argument to RelatationDataContent.update(...) should be optional #1226

Merged

Conversation

addyess
Copy link
Contributor

@addyess addyess commented May 22, 2024

Fixes the signature for RelationDataContent.update to match MutableMapping, where other is optional (a regression introduced in #1883).

The type for other has been simplified to Any. It should really be Mapping|_SupportsKeysAndGetItem[str,str] plus a minimal type that supports .values, but it was already messy pulling in _SupportsKeysAndGetItem in #1183, and we're just passing this through to MutableMapping so it doesn't seem like the tight typing is providing enough benefit to justify the complexity of the signature. typeshed has three overloads, so we could match that (as we did in #1883, just incompletely), if that is desirable.

Fixes: #1225

@addyess
Copy link
Contributor Author

addyess commented May 22, 2024

@tonyandrewmeyer and @benhoyt I appreciate your speedy review as this likely break a few releases queued up for this week.

@dimaqq
Copy link
Contributor

dimaqq commented May 23, 2024

The change makes sense, I believe Tony volunteered to tests for this.

@tonyandrewmeyer tonyandrewmeyer changed the title Allow the other argument to RelatationDataContent.update(...) to be optional fix: the other argument to RelatationDataContent.update(...) should be optional May 23, 2024
@@ -1722,7 +1712,7 @@ def __getitem__(self, key: str) -> str:
self._validate_read()
return super().__getitem__(key)

def update(self, other: _SupportsKeysAndGetItem[str, str], **kwargs: str):
def update(self, other: typing.Any = (), /, **kwargs: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL that typeshed doesn't even define dict.update

https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1029

So, all good here!

test/test_model.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dimaqq dimaqq left a comment

Choose a reason for hiding this comment

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

Super-minor/bikeshedding: I suppose the test could be more concise (either parametrised of performing all 3 updates on the same object/within same test).

Happy to have this fix!

@tonyandrewmeyer
Copy link
Contributor

tonyandrewmeyer commented May 23, 2024

Super-minor/bikeshedding: I suppose the test could be more concise (either parametrised of performing all 3 updates on the same object/within same test).

Fair point. I have never really been in the habit of using unittest.subTest for this, but now that we are (very nearly) switched over to pytest, using pytest.mark.parametrize would be cleaner.

I considered doing them all in the same test, but felt it was cleaner to have them separate, particularly if only some fail (as is the case before this PR).

@addyess
Copy link
Contributor Author

addyess commented May 23, 2024

Wow, thanks for the improved solution @dimaqq!

@dimaqq
Copy link
Contributor

dimaqq commented May 23, 2024

@tonyandrewmeyer deserves the credit. I've only reviewed the PR 🙇🏻

@addyess
Copy link
Contributor Author

addyess commented May 23, 2024

@tonyandrewmeyer deserves the credit. I've only reviewed the PR 🙇🏻

Sorry, it was late and i was blurry-eyed 👀 . Thanks so much @tonyandrewmeyer!

@addyess
Copy link
Contributor Author

addyess commented May 23, 2024

@IronCore864 Thanks so much also for offering a review

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Fix looks good, thanks @addyess. I agree that the tests have a bit too much duplication, parametrization seems like a good idea here.

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Much nicer, thanks

@tonyandrewmeyer tonyandrewmeyer merged commit 0dd27df into canonical:main May 24, 2024
25 checks passed
@addyess addyess deleted the issue/1225/relation-data-content-update branch May 24, 2024 04:00
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.

RelationDataContent should be update-able via keyword arguments only
4 participants