🌐 AI搜索 & 代理 主页
Skip to content
Draft
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
2 changes: 0 additions & 2 deletions Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,6 @@ def test_hash_disallow_instantiation(self):
support.check_disallow_instantiation(self, HASH)
support.check_disallow_instantiation(self, HASHXOF)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_readonly_types(self):
for algorithm, constructors in self.constructors_to_test.items():
# all other types have DISALLOW_INSTANTIATION
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/hashlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub mod _hashlib {
}
}

#[pyclass(with(Representable))]
#[pyclass(flags(IMMUTABLETYPE), with(Representable))]
impl PyHasher {
fn new(name: &str, d: HashWrapper) -> Self {
Self {
Expand Down Expand Up @@ -170,7 +170,7 @@ pub mod _hashlib {
}
}

#[pyclass]
#[pyclass(flags(IMMUTABLETYPE))]
impl PyHasherXof {
fn new(name: &str, d: HashXofWrapper) -> Self {
Self {
Expand Down
9 changes: 9 additions & 0 deletions vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,15 @@ impl SetAttr for PyType {
value: PySetterValue,
vm: &VirtualMachine,
) -> PyResult<()> {
// Check if type is immutable
if zelf.slots.flags.has_feature(PyTypeFlags::IMMUTABLETYPE) {
return Err(vm.new_type_error(format!(
"cannot set '{}' attribute of immutable type '{}'",
attr_name.as_str(),
zelf.name()
)));
}

// TODO: pass PyRefExact instead of &str
let attr_name = vm.ctx.intern_str(attr_name.as_str());
if let Some(attr) = zelf.get_class_attr(attr_name) {
Expand Down
Loading