-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-103395: Improve typing._GenericA
8000
lias.__dir__
coverage
#103396
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -855,6 +855,15 @@ def test_accepts_single_type(self): | |
(*tuple[int],) | ||
Unpack[Tuple[int]] | ||
|
||
def test_dir(self): | ||
dir_items = set(dir(Unpack[Tuple[int]])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_rejects_multiple_types(self): | ||
with self.assertRaises(TypeError): | ||
Unpack[Tuple[int], Tuple[str]] | ||
|
@@ -1699,6 +1708,15 @@ def test_repr(self): | |
u = Optional[str] | ||
self.assertEqual(repr(u), 'typing.Optional[str]') | ||
|
||
def test_dir(self): | ||
dir_items = set(dir(Union[str, int])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_cannot_subclass(self): | ||
with self.assertRaisesRegex(TypeError, | ||
r'Cannot subclass typing\.Union'): | ||
|
@@ -1839,6 +1857,17 @@ def test_eq_hash(self): | |
self.assertNotEqual(C, Callable[..., int]) | ||
self.assertNotEqual(C, Callable) | ||
|
||
def test_dir(self): | ||
Callable = self.Callable | ||
dir_items = set(dir(Callable[..., int])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
# TODO: add to `collections.abc.Callable`: | ||
# 'copy_with', | ||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_cannot_instantiate(self): | ||
Callable = self.Callable | ||
with self.assertRaises(TypeError): | ||
|
@@ -2151,6 +2180,15 @@ def test_repr(self): | |
self.assertEqual(repr(Literal[None]), "typing.Literal[None]") | ||
self.assertEqual(repr(Literal[1, 2, 3, 3]), "typing.Literal[1, 2, 3]") | ||
|
||
def test_dir(self): | ||
dir_items = set(dir(Literal[1, 2, 3])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_cannot_init(self): | ||
with self.assertRaises(TypeError): | ||
Literal() | ||
|
@@ -7315,6 +7353,16 @@ def test_repr(self): | |
"typing.Annotated[typing.List[int], 4, 5]" | ||
) | ||
|
||
def test_dir(self): | ||
dir_items = set(dir(Annotated[int, 4])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
'__metadata__', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the (No change requested here.) |
||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_flatten(self): | ||
A = Annotated[Annotated[int, 4], 5] | ||
self.assertEqual(A, Annotated[int, 4, 5]) | ||
|
@@ -8033,6 +8081,16 @@ class MyClass: ... | |
c = Concatenate[MyClass, P] | ||
self.assertNotEqual(c, Concatenate) | ||
|
||
def test_dir(self): | ||
P = ParamSpec('P') | ||
dir_items = set(dir(Concatenate[int, P])) | ||
for required_item in [ | ||
'__args__', '__parameters__', '__origin__', | ||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
|
||
def test_valid_uses(self): | ||
P = ParamSpec('P') | ||
T = TypeVar('T') | ||
|
@@ -8310,10 +8368,19 @@ class Foo(Generic[T]): | |
def bar(self): | ||
pass | ||
baz = 3 | ||
__magic__ = 4 | ||
|
||
# The class attributes of the original class should be visible even | ||
# in dir() of the GenericAlias. See bpo-45755. | ||
self.assertIn('bar', dir(Foo[int])) | ||
self.assertIn('baz', dir(Foo[int])) | ||
dir_items = set(dir(Foo[int])) | ||
for required_item in [ | ||
'bar', 'baz', | ||
'__args__', '__parameters__', '__origin__', | ||
'copy_with', | ||
]: | ||
with self.subTest(required_item=required_item): | ||
self.assertIn(required_item, dir_items) | ||
self.assertNotIn('__magic__', dir_items) | ||
|
||
|
||
class RevealTypeTests(BaseTestCase): | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.