Skip to content

Fix type_params lifetime in symboltable #5844

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 2 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2924,13 +2924,10 @@ def test_runtime_checkable_generic_non_protocol(self):
@runtime_checkable
class Foo[T]: ...

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_runtime_checkable_generic(self):
# @runtime_checkable
# class Foo[T](Protocol):
# def meth(self) -> T: ...
# pass
@runtime_checkable
class Foo[T](Protocol):
def meth(self) -> T: ...

class Impl:
def meth(self) -> int: ...
Expand All @@ -2945,9 +2942,9 @@ def method(self) -> int: ...
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_pep695_generics_can_be_runtime_checkable(self):
# @runtime_checkable
# class HasX(Protocol):
# x: int
@runtime_checkable
class HasX(Protocol):
x: int

class Bar[T]:
x: T
Expand Down Expand Up @@ -2987,22 +2984,20 @@ def f():

self.assertIsInstance(f, HasCallProtocol)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_inheritance_from_nominal(self):
class C: pass

# class BP(Protocol): pass
class BP(Protocol): pass

# with self.assertRaises(TypeError):
# class P(C, Protocol):
# pass
# with self.assertRaises(TypeError):
# class Q(Protocol, C):
# pass
# with self.assertRaises(TypeError):
# class R(BP, C, Protocol):
# pass
with self.assertRaises(TypeError):
class P(C, Protocol):
pass
with self.assertRaises(TypeError):
class Q(Protocol, C):
pass
with self.assertRaises(TypeError):
class R(BP, C, Protocol):
pass

class D(BP, C): pass

Expand All @@ -3014,7 +3009,7 @@ class E(C, BP): pass
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_instantiation(self):
# class P(Protocol): pass
class P(Protocol): pass

with self.assertRaises(TypeError):
P()
Expand Down Expand Up @@ -3042,16 +3037,14 @@ class CG(PG[T]): pass
with self.assertRaises(TypeError):
CG[int](42)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_protocol_defining_init_does_not_get_overridden(self):
# check that P.__init__ doesn't get clobbered
# see https://bugs.python.org/issue44807

# class P(Protocol):
# x: int
# def __init__(self, x: int) -> None:
# self.x = x
class P(Protocol):
x: int
def __init__(self, x: int) -> None:
self.x = x
class C: pass

c = C()
Expand Down Expand Up @@ -3478,9 +3471,9 @@ def __getattr__(self, attr):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_weird_caching_with_issubclass_after_isinstance_pep695(self):
# @runtime_checkable
# class Spam[T](Protocol):
# x: T
@runtime_checkable
class Spam[T](Protocol):
x: T

class Eggs[T]:
def __init__(self, x: T) -> None:
Expand Down
11 changes: 6 additions & 5 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ fn eprint_location(zelf: &Compiler<'_>) {
}

/// Better traceback for internal error
#[track_caller]
fn unwrap_internal<T>(zelf: &Compiler<'_>, r: InternalResult<T>) -> T {
if let Err(ref r_err) = r {
eprintln!("=== CODEGEN PANIC INFO ===");
Expand Down Expand Up @@ -1705,11 +1706,6 @@ impl Compiler<'_> {
func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
}

// Pop the special type params symbol table
if type_params.is_some() {
self.pop_symbol_table();
}

self.emit_load_const(ConstantData::Code {
code: Box::new(code),
});
Expand All @@ -1728,6 +1724,11 @@ impl Compiler<'_> {
};
self.compile_normal_call(call);

// Pop the special type params symbol table
if type_params.is_some() {
self.pop_symbol_table();
}

self.apply_decorators(decorator_list);

self.store_name(name)
Expand Down
2 changes: 1 addition & 1 deletion vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl PyMemoryView {

#[pygetset]
fn f_contiguous(&self, vm: &VirtualMachine) -> PyResult<bool> {
// TODO: fortain order
// TODO: column-major order
self.try_not_released(vm)
.map(|_| self.desc.ndim() <= 1 && self.desc.is_contiguous())
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/protocol/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl BufferDescriptor {
self.dim_desc.iter().any(|(shape, _, _)| *shape == 0)
}

// TODO: support fortain order
// TODO: support column-major order
}

pub trait BufferResizeGuard {
Expand Down
Loading