-
Notifications
You must be signed in to change notification settings - Fork 283
Change the typing spec around string references #2144
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
Draft
davidhalter
wants to merge
5
commits into
python:main
Choose a base branch
from
davidhalter:string-annotations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7627175
Change the typing spec around string references
davidhalter d08c226
Improve the wording around string references in the spec
davidhalter 070312d
Remove error types
davidhalter 41fc20c
Update docs/spec/annotations.rst
davidhalter ea921e8
Merge remote-tracking branch 'origin/main' into string-annotations
davidhalter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this example would be even more illuminating if placed before
def intThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think I should move both x and y? In 3.14 it should not matter where the annotations are defined, but type checkers might still work a bit different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're aiming for this test to really clarify the behavior, I think having a version of both x and y, both before and after
def int, would be useful. Their behavior should not be the same. The stringified version should refer todef intregardless of location; the non stringified version will refer to the globalintif beforedef intUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how I understand Python 3.14 works. Maybe @JelleZijlstra can clarify. If I understand it correctly, both before and after would refer to the
def int.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3.14 behavior would be that before or after
def int, the annotationintrefers todef int. So that should be the behavior of the stringified"int"annotation.The behavior of the unstringified
intannotation should depend on the Python version. Checking under 3.14 it should behave the same as the stringified annotation. Checking under an earlier Python, it should resolve as I described above.I don't interpret this PR to be specifying that non-stringified annotations in Python versions earlier than 3.14 should behave as if under 3.14.
So you're right -- my comment above was making an unwarranted assumption that the conformance tests specify behavior on an older version of Python. But there's no reason that should be assumed. I think this highlights an existing problem, which is that it's not clear (or documented anywhere, as far as I can find) what Python version the conformance tests should assume.
If the conformance tests should always be assumed to check under the most recent Python, then stringified and non-stringified annotations should behave the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Now I'm just not sure what to do. 😄 What would you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably for purposes of this PR the best option is to avoid checking behavior that should depend on the Python version? So that implies avoiding an unstringified
intannotation beforedef int. Which is fine -- there already isn't one. So just ignore that part of my suggestion :)I also think the conformance tests should ideally be clearer about Python version, and probably include a facility for explicitly checking some files under a specified version. But that's a bigger project, definitely out of scope for this PR.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think having
z: "int"beforedef int, as well as thex: "int"after (my original suggestion in this thread) is useful, and doesn't depend on Python version.It's the expanded idea of also having
foo: intbeforedef intthat would depend on Python version, and thus isn't worth doing here.