forked from Rust-related/RustPython
remove vm.ctx.new_namespace
This commit is contained in:
@@ -2,7 +2,7 @@ use super::PyTypeRef;
|
||||
use crate::{
|
||||
function::{IntoPyObject, KwArgs},
|
||||
slots::SlotConstructor,
|
||||
PyClassImpl, PyContext, PyResult, PyValue, VirtualMachine,
|
||||
PyClassImpl, PyContext, PyRef, PyResult, PyValue, VirtualMachine,
|
||||
};
|
||||
|
||||
/// A simple attribute-based namespace.
|
||||
@@ -30,6 +30,12 @@ impl SlotConstructor for PyNamespace {
|
||||
}
|
||||
}
|
||||
|
||||
impl PyNamespace {
|
||||
pub fn new_ref(ctx: &PyContext) -> PyRef<Self> {
|
||||
PyRef::new_ref(Self, ctx.types.namespace_type.clone(), Some(ctx.new_dict()))
|
||||
}
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE, HAS_DICT), with(SlotConstructor))]
|
||||
impl PyNamespace {}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ macro_rules! extend_class {
|
||||
macro_rules! py_namespace {
|
||||
( $vm:expr, { $($name:expr => $value:expr),* $(,)* }) => {
|
||||
{
|
||||
let namespace = $vm.ctx.new_namespace();
|
||||
let namespace = $crate::builtins::PyNamespace::new_ref(&$vm.ctx).into();
|
||||
$(
|
||||
$vm.__module_set_attr(&namespace, $name, $value).unwrap();
|
||||
)*
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::{
|
||||
bytearray, bytes,
|
||||
code::{self, PyCode},
|
||||
getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetSet},
|
||||
namespace::PyNamespace,
|
||||
object, pystr,
|
||||
set::{self, PyFrozenSet},
|
||||
PyBaseExceptionRef, PyBoundMethod, PyDict, PyDictRef, PyEllipsis, PyFloat, PyInt, PyIntRef,
|
||||
@@ -250,14 +249,6 @@ impl PyContext {
|
||||
create_type_with_slots(name, &self.types.type_type, base, slots)
|
||||
}
|
||||
|
||||
pub fn new_namespace(&self) -> PyObjectRef {
|
||||
PyObject::new(
|
||||
PyNamespace,
|
||||
self.types.namespace_type.clone(),
|
||||
Some(self.new_dict()),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn new_stringref(&self, s: String) -> pystr::PyStrRef {
|
||||
PyRef::new_ref(pystr::PyStr::from(s), self.types.str_type.clone(), None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user