gh-138764: annotationlib - Check if the VALUE_WITH_FAKE_GLOBALS format is implemented before calling an __annotate__ function with empty fake globals#138788
Closed
DavidCEllis wants to merge 5 commits intopython:mainfrom
Conversation
| annotate.assert_called_once_with(Format.FORWARDREF) | ||
|
|
||
| # Test the call on the function with fake globals | ||
| new_annotate.assert_called_once_with(Format.VALUE_WITH_FAKE_GLOBALS) |
Member
There was a problem hiding this comment.
Not a fan of these tests as they're asserting details of the implementation, not the observable behavior. Is there a way to write a test that's closer to your use case?
Contributor
Author
There was a problem hiding this comment.
I suppose this could instead test multiple annotate functions that provide only those formats?
Let me know if you prefer this or #138803 and I'll modify the tests for the relevant PR.
Contributor
Author
|
Closing in favour of the approach in #138803 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an issue where user defined
__annotate__functions that do not support a specific format would be called with fake globals in a way that they couldn't correctly raiseNotImplementedError.One downside is that some
annotatefunctions that may have appeared to 'work' before now correctly fail. It's possible we may want to add some kind of fallback toVALUEannotations in these cases, but calling with fake globals as it does now would only accidentally succeed depending on exactly how the function performs the comparisons.Current:
{'x': 'str'}With patch:
But change the comparison to check if the format is in a set:
Current:
With patch:
call_annotate_functionshould checkVALUE_WITH_FAKE_GLOBALSis implemented before calling in a namespace with empty fake globals #138764