-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support type[a.X]
with qualified class names
#14825
Merged
Merged
Changes from all commits
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
89 changes: 89 additions & 0 deletions
89
crates/red_knot_python_semantic/resources/mdtest/type_of/basic.md
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,89 @@ | ||
# type special form | ||
|
||
## Class literal | ||
|
||
```py | ||
class A: ... | ||
|
||
def f() -> type[A]: | ||
return A | ||
|
||
reveal_type(f()) # revealed: type[A] | ||
``` | ||
|
||
## Nested class literal | ||
|
||
```py | ||
class A: | ||
class B: ... | ||
|
||
def f() -> type[A.B]: | ||
return A.B | ||
|
||
reveal_type(f()) # revealed: type[B] | ||
``` | ||
|
||
## Deeply nested class literal | ||
|
||
```py | ||
class A: | ||
class B: | ||
class C: ... | ||
|
||
def f() -> type[A.B.C]: | ||
return A.B.C | ||
|
||
reveal_type(f()) # revealed: type[C] | ||
``` | ||
|
||
## Class literal from another module | ||
|
||
```py | ||
from a import A | ||
|
||
def f() -> type[A]: | ||
return A | ||
|
||
reveal_type(f()) # revealed: type[A] | ||
``` | ||
|
||
```py path=a.py | ||
class A: ... | ||
``` | ||
|
||
## Qualified class literal from another module | ||
|
||
```py | ||
import a | ||
|
||
def f() -> type[a.B]: | ||
return a.B | ||
|
||
reveal_type(f()) # revealed: type[B] | ||
``` | ||
|
||
```py path=a.py | ||
class B: ... | ||
``` | ||
|
||
## Deeply qualified class literal from another module | ||
|
||
```py path=a/test.py | ||
import a.b | ||
|
||
# TODO: no diagnostic | ||
# error: [unresolved-attribute] | ||
def f() -> type[a.b.C]: | ||
# TODO: no diagnostic | ||
# error: [unresolved-attribute] | ||
return a.b.C | ||
|
||
reveal_type(f()) # revealed: @Todo(unsupported type[X] special form) | ||
``` | ||
|
||
```py path=a/__init__.py | ||
``` | ||
|
||
```py path=a/b.py | ||
class C: ... | ||
``` |
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
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.
I left this as a TODO because I think this is not specific to
type[]
. Theunresolved-attribute
error I get is:which suggests that our import logic is binding
a
asa.b
instead ofa
. Am I interpreting that right?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.
Yes, it looks like you are! I think this is a previously-not-known bug, unless @AlexWaygood was already aware of it. Want to file an issue (labeled
red-knot
)? Could also be an interesting one for you to look into, would get you some exposure to the module resolver, which I don't think any of the other tasks do.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 think I already knew about it, and I think we already have a TODO about it... whether we have an issue is another question... it's late here, so I won't look into whether we do or don't this evening :-)
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.
Opened #14826, can close it as a dup if it turns out we have another one already open