Compare commits

...

7 Commits

Author SHA1 Message Date
20c053a3c0 Refactor PySetterValue handling in object and type modules
Some checks failed
PR Review / review (pull_request) Failing after 3s
CI / Run snippets and cpython tests (ubuntu-latest) (pull_request) Failing after 5m54s
CI / Check Rust code with rustfmt and clippy (pull_request) Failing after 45s
CI / Run tests under miri (pull_request) Successful in 6m24s
CI / Check the WASM package and demo (pull_request) Failing after 4m44s
CI / Run rust tests (ubuntu-latest) (pull_request) Failing after 4m38s
CI / Ensure compilation on various targets (pull_request) Failing after 1m6s
CI / Run snippets and cpython tests on wasm-wasi (pull_request) Successful in 4m46s
CI / Run rust tests (macos-latest) (pull_request) Has been cancelled
CI / Run rust tests (windows-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (pull_request) Has been cancelled
- Update object_set_dict to use new PySetterValue variants
- Modify getset.rs to handle PySetterValue::Delete
- Add delete_dict method to PyObject
- Adjust type.rs to use new PySetterValue semantics
2025-02-09 23:26:36 +09:00
Zion
6181bf4a7a Add delete for object_set_dict
Some checks failed
CI / Run rust tests (ubuntu-latest) (pull_request) Failing after 5m7s
CI / Ensure compilation on various targets (pull_request) Failing after 1m15s
CI / Check the WASM package and demo (pull_request) Failing after 5m47s
PR Review / review (pull_request) Failing after 4s
CI / Run snippets and cpython tests (ubuntu-latest) (pull_request) Failing after 5m21s
CI / Check Rust code with rustfmt and clippy (pull_request) Failing after 29s
CI / Run tests under miri (pull_request) Failing after 4m25s
CI / Run snippets and cpython tests on wasm-wasi (pull_request) Failing after 3m0s
CI / Run rust tests (macos-latest) (pull_request) Has been cancelled
CI / Run rust tests (windows-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (pull_request) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (pull_request) Has been cancelled
2025-02-08 17:24:31 +09:00
b333ffa781 merge upstream
Some checks failed
CI / Run rust tests (macos-latest) (push) Has been cancelled
CI / Run rust tests (ubuntu-latest) (push) Has been cancelled
CI / Run rust tests (windows-latest) (push) Has been cancelled
CI / Ensure compilation on various targets (push) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (ubuntu-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (push) Has been cancelled
CI / Check Rust code with rustfmt and clippy (push) Has been cancelled
CI / Run tests under miri (push) Has been cancelled
CI / Check the WASM package and demo (push) Has been cancelled
CI / Run snippets and cpython tests on wasm-wasi (push) Has been cancelled
2025-02-08 16:33:07 +09:00
308b95ec13 Update .github/workflows/ai-review.yml 2025-01-11 01:53:46 +09:00
5f77ce5b4f Update .github/workflows/ai-review.yml 2025-01-11 00:44:09 +09:00
4da57d42de Update .github/workflows/ai-review.yml
Some checks failed
CI / Run rust tests (macos-latest) (push) Has been cancelled
CI / Run rust tests (windows-latest) (push) Has been cancelled
CI / Ensure compilation on various targets (push) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (ubuntu-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (push) Has been cancelled
CI / Check Rust code with rustfmt and clippy (push) Has been cancelled
CI / Run tests under miri (push) Has been cancelled
CI / Check the WASM package and demo (push) Has been cancelled
CI / Run snippets and cpython tests on wasm-wasi (push) Has been cancelled
CI / Run rust tests (ubuntu-latest) (push) Has been cancelled
2025-01-10 13:54:55 +09:00
2777588bb4 Add ci
Some checks failed
CI / Run rust tests (macos-latest) (push) Has been cancelled
CI / Run rust tests (windows-latest) (push) Has been cancelled
CI / Ensure compilation on various targets (push) Has been cancelled
CI / Run snippets and cpython tests (macos-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (ubuntu-latest) (push) Has been cancelled
CI / Run snippets and cpython tests (windows-latest) (push) Has been cancelled
CI / Check Rust code with rustfmt and clippy (push) Has been cancelled
CI / Run tests under miri (push) Has been cancelled
CI / Check the WASM package and demo (push) Has been cancelled
CI / Run snippets and cpython tests on wasm-wasi (push) Has been cancelled
CI / Run rust tests (ubuntu-latest) (push) Has been cancelled
2025-01-10 11:48:55 +09:00
5 changed files with 53 additions and 6 deletions

23
.github/workflows/ai-review.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: PR Review
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: AI Code Review
uses: gitea-actions/ai-reviewer@v0.6
with:
access-token: ${{ secrets.ACCESS_TOKEN }}
full-context-model: "gpt-4o"
full-context-api-key: ${{ secrets.OPENAI_API_KEY }}
single-chunk-model: "claude-3-5-sonnet"
single-chunk-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
exclude-files: "*.md,*.yaml"

View File

@@ -495,9 +495,18 @@ pub fn object_get_dict(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict
obj.dict()
.ok_or_else(|| vm.new_attribute_error("This object has no __dict__".to_owned()))
}
pub fn object_set_dict(obj: PyObjectRef, dict: PyDictRef, vm: &VirtualMachine) -> PyResult<()> {
pub fn object_set_dict(obj: PyObjectRef, dict: PySetterValue<PyDictRef>, vm: &VirtualMachine) -> PyResult<()> {
match dict {
PySetterValue::Assign(dict) => {
obj.set_dict(dict)
.map_err(|_| vm.new_attribute_error("This object has no __dict__".to_owned()))
}
PySetterValue::Delete => {
obj.delete_dict()
.map_err(|_| vm.new_attribute_error("This object has no deletable __dict__".to_owned()))
}
}
}
pub fn init(ctx: &Context) {

View File

@@ -1288,7 +1288,7 @@ fn subtype_set_dict(obj: PyObjectRef, value: PyObjectRef, vm: &VirtualMachine) -
descr_set(&descr, obj, PySetterValue::Assign(value), vm)
}
None => {
object::object_set_dict(obj, value.try_into_value(vm)?, vm)?;
object::object_set_dict(obj, PySetterValue::Delete, vm)?;
Ok(())
}
}

View File

@@ -36,8 +36,10 @@ where
{
#[inline]
fn from_setter_value(vm: &VirtualMachine, obj: PySetterValue) -> PyResult<Self> {
let obj = obj.ok_or_else(|| vm.new_type_error("can't delete attribute".to_owned()))?;
T::try_from_object(vm, obj)
match obj {
PySetterValue::Assign(obj) => T::try_from_object(vm, obj),
PySetterValue::Delete => T::try_from_object(vm, vm.ctx.none()),
}
}
}

View File

@@ -717,6 +717,19 @@ impl PyObject {
}
}
pub fn delete_dict(&self) -> Result<(), ()> {
match self.instance_dict() {
Some(_) => {
unsafe {
let ptr = self as *const _ as *mut PyObject;
(*ptr).0.dict = None;
}
Ok(())
}
None => Err(()),
}
}
#[inline(always)]
pub fn payload_if_subclass<T: crate::PyPayload>(&self, vm: &VirtualMachine) -> Option<&T> {
if self.class().fast_issubclass(T::class(&vm.ctx)) {