Conversation
|
This comment was marked as outdated.
This comment was marked as outdated.
This one is a crash:
|
|
OMG 😅 I’ll check the panic in the mypy primer first and then request review again. |
|
I'm not sure if the panic is due to your PR. It is the same that @carljm has seen on other mypy primer projects. |
It shows that this PR causes us to panic on code that we did not previously panic on. Maybe that's acceptable if we want to defer adding cycle handling to the relevant function for now, but it's going to lead to pretty confusing diffs if we include projects we panic on in mypy_primer. I think at the very least we should remove the project from the list in the workflow file of projects we run on in CI if we're going to start panicking on that project: ruff/.github/workflows/mypy_primer.yaml Line 71 in 755ece0 but also: adding cycle handling to a query probably isn't that difficult, and it's nice to at least not increase the amount of code we panic on. @cake-monotone, you can see an example of how to do it here: #16958 :-) I'd imagine adding cycle handling to |
|
Agree. @carljm might be able to prioritize the fix real quick to unblock this PR |
It's okay! I'll try to fix it soon...!
I just need to define a custom |
I think that's correct, yes! |
|
Ah... it's still not working. the mypy primer still panics 😢 Here's the commit if you'd like to take a look: |
|
hmm, okay, we may need @carljm's advice on how to fix this; he's the fixpoint expert :-) |
This comment was marked as outdated.
This comment was marked as outdated.
|
It turns out that there were actually two functions causing the panic: @carjim Hmm, just checking, are you planning to open a separate PR to implement |
MichaReiser
left a comment
There was a problem hiding this comment.
I'd suggest fixing the cycles as a separate PR
|
Sorry for the long delay on this PR. I've been pretty drained over the past two weeks due to some other things going on, and didn’t have the energy to polish it to a state I was happy with. Anyway, since the last review, a lot has changed — including improvements in handling dynamic types, fixes for incorrect enclosing class inference, and support for generic classes. I'd really appreciate it if you could take another look. :) |
There was a problem hiding this comment.
This looks fantastic! Just a few nits. I pushed fixes for some of these since I'd already made the changes locally for testing. I think the main thing left to address is more tests for use of super with generics, and addressing the debug assertion that I don't think is correct. Also looks like it needs a rebase and to address a conflict in types.rs. Please let me know if you don't have time to address this and I can find some time! I want to get this landed and not have it accumulate more conflicts.
crates/red_knot_python_semantic/resources/mdtest/class/super.md
Outdated
Show resolved
Hide resolved
|
Excellent work on this PR, thank you!! |
* main: [red-knot] Support `super` (#17174)
Summary
closes #16615
This PR includes:
Type::BoundSuperType::BoundSuper, resolving attributes by traversing the MRO starting from the specified classpivot_classandowner) forsuper()when it is used without argumentsWhen
super(..)appears in code, it can be inferred into one of the following:Type::Unknown: when a runtime error would occur (e.g. callingsuper()out of method scope, or when parameter validation insidesuperfails)KnownClass::Super::to_instance(): when the result is an unbound super object or when a dynamic type is used as parameters (MRO traversing is meaningless)Type::BoundSuper: the common case, representing a properly constructedsuperinstance that is ready for MRO traversal and attribute resolutionTerminology
Python defines the terms bound super object and unbound super object.
An unbound super object is created when
superis called with only one argument (e.g.super(A)). This object may later be bound via thesuper.__get__method. However, this form is rarely used in practice.A bound super object is created either by calling
super(pivot_class, owner)or by using the implicit formsuper(), where both arguments are inferred from the context. This is the most common usage.Follow-ups
super()calls that would result in runtime errors (marked as TODO)Type::BoundSuperTest Plan
mdtest/class/super.md