Skip to content

Commit c8eff6e

Browse files
committed
clean up asyncgen
1 parent 107a640 commit c8eff6e

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

vm/src/builtins/asyncgenerator.rs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl PyPayload for PyAsyncGen {
2626
}
2727
}
2828

29-
#[pyclass(with(Constructor, Representable))]
29+
#[pyclass(with(PyRef, Constructor, Representable))]
3030
impl PyAsyncGen {
3131
pub fn as_coro(&self) -> &Coro {
3232
&self.inner
@@ -49,35 +49,60 @@ impl PyAsyncGen {
4949
self.inner.set_name(name)
5050
}
5151

52+
#[pygetset]
53+
fn ag_await(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
54+
self.inner.frame().yield_from_target()
55+
}
56+
#[pygetset]
57+
fn ag_frame(&self, _vm: &VirtualMachine) -> FrameRef {
58+
self.inner.frame()
59+
}
60+
#[pygetset]
61+
fn ag_running(&self, _vm: &VirtualMachine) -> bool {
62+
self.inner.running()
63+
}
64+
#[pygetset]
65+
fn ag_code(&self, _vm: &VirtualMachine) -> PyRef<PyCode> {
66+
self.inner.frame().code.clone()
67+
}
68+
69+
#[pyclassmethod(magic)]
70+
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
71+
PyGenericAlias::new(cls, args, vm)
72+
}
73+
}
74+
75+
#[pyclass]
76+
impl PyRef<PyAsyncGen> {
5277
#[pymethod(magic)]
53-
fn aiter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
54-
zelf
78+
fn aiter(self, _vm: &VirtualMachine) -> PyRef<PyAsyncGen> {
79+
self
5580
}
5681

5782
#[pymethod(magic)]
58-
fn anext(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyAsyncGenASend {
59-
Self::asend(zelf, vm.ctx.none(), vm)
83+
fn anext(self, vm: &VirtualMachine) -> PyAsyncGenASend {
84+
Self::asend(self, vm.ctx.none(), vm)
6085
}
6186

6287
#[pymethod]
63-
fn asend(zelf: PyRef<Self>, value: PyObjectRef, _vm: &VirtualMachine) -> PyAsyncGenASend {
88+
fn asend(self, value: PyObjectRef, _vm: &VirtualMachine) -> PyAsyncGenASend {
6489
PyAsyncGenASend {
65-
ag: zelf,
90+
ag: self,
6691
state: AtomicCell::new(AwaitableState::Init),
6792
value,
6893
}
6994
}
7095

7196
#[pymethod]
7297
fn athrow(
73-
zelf: PyRef<Self>,
98+
self,
7499
exc_type: PyObjectRef,
75100
exc_val: OptionalArg,
76101
exc_tb: OptionalArg,
77102
vm: &VirtualMachine,
78103
) -> PyAsyncGenAThrow {
79104
PyAsyncGenAThrow {
80-
ag: zelf,
105+
ag: self,
81106
aclose: false,
82107
state: AtomicCell::new(AwaitableState::Init),
83108
value: (
@@ -89,9 +114,9 @@ impl PyAsyncGen {
89114
}
90115

91116
#[pymethod]
92-
fn aclose(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyAsyncGenAThrow {
117+
fn aclose(self, vm: &VirtualMachine) -> PyAsyncGenAThrow {
93118
PyAsyncGenAThrow {
94-
ag: zelf,
119+
ag: self,
95120
aclose: true,
96121
state: AtomicCell::new(AwaitableState::Init),
97122
value: (
@@ -101,28 +126,6 @@ impl PyAsyncGen {
101126
),
102127
}
103128
}
104-
105-
#[pygetset]
106-
fn ag_await(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
107-
self.inner.frame().yield_from_target()
108-
}
109-
#[pygetset]
110-
fn ag_frame(&self, _vm: &VirtualMachine) -> FrameRef {
111-
self.inner.frame()
112-
}
113-
#[pygetset]
114-
fn ag_running(&self, _vm: &VirtualMachine) -> bool {
115-
self.inner.running()
116-
}
117-
#[pygetset]
118-
fn ag_code(&self, _vm: &VirtualMachine) -> PyRef<PyCode> {
119-
self.inner.frame().code.clone()
120-
}
121-
122-
#[pyclassmethod(magic)]
123-
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
124-
PyGenericAlias::new(cls, args, vm)
125-
}
126129
}
127130

128131
impl Representable for PyAsyncGen {

0 commit comments

Comments
 (0)