Skip to content

Commit 185a1ef

Browse files
committed
__doc__ handing in the right way
1 parent c71c78c commit 185a1ef

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

Lib/test/test_typing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5269,7 +5269,6 @@ def test_weakref_all(self):
52695269
for t in things:
52705270
self.assertEqual(weakref.ref(t)(), t)
52715271

5272-
@unittest.expectedFailure # TODO: RUSTPYTHON
52735272
def test_parameterized_slots(self):
52745273
T = TypeVar('T')
52755274
class C(Generic[T]):
@@ -5289,7 +5288,6 @@ def foo(x: C['C']): ...
52895288
self.assertEqual(get_type_hints(foo, globals(), locals())['x'], C[C])
52905289
self.assertEqual(copy(C[int]), deepcopy(C[int]))
52915290

5292-
@unittest.expectedFailure # TODO: RUSTPYTHON
52935291
def test_parameterized_slots_dict(self):
52945292
T = TypeVar('T')
52955293
class D(Generic[T]):

crates/codegen/src/compile.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,10 +2679,12 @@ impl Compiler {
26792679
let qualname_name = self.name("__qualname__");
26802680
emit!(self, Instruction::StoreLocal(qualname_name));
26812681

2682-
// Store __doc__
2683-
self.load_docstring(doc_str);
2684-
let doc = self.name("__doc__");
2685-
emit!(self, Instruction::StoreLocal(doc));
2682+
// Store __doc__ only if there's an explicit docstring
2683+
if let Some(doc) = doc_str {
2684+
self.emit_load_const(ConstantData::Str { value: doc.into() });
2685+
let doc_name = self.name("__doc__");
2686+
emit!(self, Instruction::StoreLocal(doc_name));
2687+
}
26862688

26872689
// Store __firstlineno__ (new in Python 3.12+)
26882690
self.emit_load_const(ConstantData::Integer {
@@ -2876,17 +2878,6 @@ impl Compiler {
28762878
self.store_name(name)
28772879
}
28782880

2879-
fn load_docstring(&mut self, doc_str: Option<String>) {
2880-
// TODO: __doc__ must be default None and no bytecode unless it is Some
2881-
// Duplicate top of stack (the function or class object)
2882-
2883-
// Doc string value:
2884-
self.emit_load_const(match doc_str {
2885-
Some(doc) => ConstantData::Str { value: doc.into() },
2886-
None => ConstantData::None, // set docstring None if not declared
2887-
});
2888-
}
2889-
28902881
fn compile_while(&mut self, test: &Expr, body: &[Stmt], orelse: &[Stmt]) -> CompileResult<()> {
28912882
let while_block = self.new_block();
28922883
let else_block = self.new_block();

crates/vm/src/builtins/type.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,9 @@ impl Constructor for PyType {
11991199
});
12001200

12011201
let attr_name = vm.ctx.intern_str(member.to_string());
1202-
if !typ.has_attr(attr_name) {
1203-
typ.set_attr(attr_name, member_descriptor.into());
1204-
}
1205-
1202+
// __slots__ attributes always get a member descriptor
1203+
// (this overrides any inherited attribute from MRO)
1204+
typ.set_attr(attr_name, member_descriptor.into());
12061205
offset += 1;
12071206
}
12081207
}

0 commit comments

Comments
 (0)