Skip to content

Commit 8a6ed4e

Browse files
youknowoneSnowapril
authored andcommitted
remove vm.ctx.new_namespace
1 parent dca52d8 commit 8a6ed4e

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

vm/src/builtins/namespace.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::PyTypeRef;
22
use crate::{
33
function::{IntoPyObject, KwArgs},
44
slots::SlotConstructor,
5-
PyClassImpl, PyContext, PyResult, PyValue, VirtualMachine,
5+
PyClassImpl, PyContext, PyRef, PyResult, PyValue, VirtualMachine,
66
};
77

88
/// A simple attribute-based namespace.
@@ -30,6 +30,12 @@ impl SlotConstructor for PyNamespace {
3030
}
3131
}
3232

33+
impl PyNamespace {
34+
pub fn new_ref(ctx: &PyContext) -> PyRef<Self> {
35+
PyRef::new_ref(Self, ctx.types.namespace_type.clone(), Some(ctx.new_dict()))
36+
}
37+
}
38+
3339
#[pyimpl(flags(BASETYPE, HAS_DICT), with(SlotConstructor))]
3440
impl PyNamespace {}
3541

vm/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ macro_rules! extend_class {
5656
macro_rules! py_namespace {
5757
( $vm:expr, { $($name:expr => $value:expr),* $(,)* }) => {
5858
{
59-
let namespace = $vm.ctx.new_namespace();
59+
let namespace = $crate::builtins::PyNamespace::new_ref(&$vm.ctx).into();
6060
$(
6161
$vm.__module_set_attr(&namespace, $name, $value).unwrap();
6262
)*

vm/src/pyobject.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
bytearray, bytes,
1111
code::{self, PyCode},
1212
getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet},
13-
namespace::PyNamespace,
1413
object, pystr,
1514
set::{self, PyFrozenSet},
1615
PyBaseExceptionRef, PyBoundMethod, PyDict, PyDictRef, PyEllipsis, PyFloat, PyInt, PyIntRef,
@@ -250,14 +249,6 @@ impl PyContext {
250249
create_type_with_slots(name, &self.types.type_type, base, slots)
251250
}
252251

253-
pub fn new_namespace(&self) -> PyObjectRef {
254-
PyObject::new(
255-
PyNamespace,
256-
self.types.namespace_type.clone(),
257-
Some(self.new_dict()),
258-
)
259-
}
260-
261252
pub(crate) fn new_stringref(&self, s: String) -> pystr::PyStrRef {
262253
PyRef::new_ref(pystr::PyStr::from(s), self.types.str_type.clone(), None)
263254
}

0 commit comments

Comments
 (0)