-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Add typing_extensions.get_annotations #423
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9e03f12
Direct copy of stdlib get_annotations
JelleZijlstra a2a467b
Backport current version of annotations.get_annotations()
JelleZijlstra ea971b5
docs
JelleZijlstra 35f68cf
lints
JelleZijlstra 2f2c3a6
include inspect helpers in sdist
JelleZijlstra f43e4b6
Update src/typing_extensions.py
JelleZijlstra 73e2263
Update src/typing_extensions.py
JelleZijlstra 9c503a9
Drop separate test files
JelleZijlstra f8d8e95
Apply suggestions from code review
JelleZijlstra 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ name = "Guido van Rossum, Jukka Lehtosalo, Łukasz Langa, Michael Lee" | |
email = "[email protected]" | ||
|
||
[tool.flit.sdist] | ||
include = ["CHANGELOG.md", "README.md", "tox.ini", "*/*test*.py"] | ||
include = ["CHANGELOG.md", "README.md", "tox.ini", "*/*test*.py", "*/*inspect*.py"] | ||
exclude = [] | ||
|
||
[tool.ruff] | ||
|
@@ -83,7 +83,7 @@ select = [ | |
|
||
# Ignore various "modernization" rules that tell you off for importing/using | ||
# deprecated things from the typing module, etc. | ||
ignore = ["UP006", "UP007", "UP013", "UP014", "UP019", "UP035", "UP038"] | ||
ignore = ["UP006", "UP007", "UP013", "UP014", "UP019", "UP035", "UP037", "UP038"] | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"!src/typing_extensions.py" = [ | ||
|
@@ -98,4 +98,10 @@ ignore = ["UP006", "UP007", "UP013", "UP014", "UP019", "UP035", "UP038"] | |
|
||
[tool.ruff.lint.isort] | ||
extra-standard-library = ["tomllib"] | ||
known-first-party = ["typing_extensions", "_typed_dict_test_helper"] | ||
known-first-party = [ | ||
"typing_extensions", | ||
"_typed_dict_test_helper", | ||
"_inspect_stock_annotations", | ||
"_inspect_stringized_annotations", | ||
"_inspect_stringized_annotations_2", | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
a:int=3 | ||
b:str="foo" | ||
|
||
class MyClass: | ||
a:int=4 | ||
b:str="bar" | ||
def __init__(self, a, b): | ||
self.a = a | ||
self.b = b | ||
def __eq__(self, other): | ||
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b | ||
|
||
def function(a:int, b:str) -> MyClass: | ||
return MyClass(a, b) | ||
|
||
|
||
def function2(a:int, b:"str", c:MyClass) -> MyClass: | ||
pass | ||
|
||
|
||
def function3(a:"int", b:"str", c:"MyClass"): | ||
pass | ||
|
||
|
||
class UnannotatedClass: | ||
pass | ||
|
||
def unannotated_function(a, b, c): pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
a:int=3 | ||
b:str="foo" | ||
|
||
class MyClass: | ||
a:int=4 | ||
b:str="bar" | ||
def __init__(self, a, b): | ||
self.a = a | ||
self.b = b | ||
def __eq__(self, other): | ||
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b | ||
|
||
def function(a:int, b:str) -> MyClass: | ||
return MyClass(a, b) | ||
|
||
|
||
def function2(a:int, b:"str", c:MyClass) -> MyClass: | ||
pass | ||
|
||
|
||
def function3(a:"int", b:"str", c:"MyClass"): | ||
pass | ||
|
||
|
||
class UnannotatedClass: | ||
pass | ||
|
||
def unannotated_function(a, b, c): pass | ||
|
||
class MyClassWithLocalAnnotations: | ||
mytype = int | ||
x: mytype |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from __future__ import annotations | ||
|
||
|
||
def foo(a, b, c): pass |
Oops, something went wrong.
Oops, something went wrong.
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.
In #151, the consensus seemed to be that we shouldn't add new "data files" to the src directory for usage in tests, because these will end up in the site-packages directory for people who've installed typing_extensions. Should we just store these as strings in test_typing_extensions.py, like we did for the data files in that PR?
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 might also be time to split the test file, as it's approaching 10k lines.
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.
Maybe we could have an
src/test_typing_extensons
directory: then it's only a single importable module insite-packages
, but we'd be able to split it up so that it doesn't get too huge.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 like the idea of making a test directory. I'll send a separate PR for that.
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 tried this and I think it's not worth it. I like to simply run
python test_typing_extensions.py
to run the test suite; that would no longer work with a package. I'll move the test files from this PR intoexec()
calls instead.