Compare commits

..

7 Commits

Author SHA1 Message Date
20c053a3c0 Refactor PySetterValue handling in object and type modules
- 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 2025-02-08 17:24:31 +09:00
b333ffa781 merge upstream 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 2025-01-10 13:54:55 +09:00
2777588bb4 Add ci 2025-01-10 11:48:55 +09:00
7 changed files with 77 additions and 30 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"

32
Cargo.lock generated
View File

@@ -1170,9 +1170,9 @@ dependencies = [
[[package]]
name = "malachite"
version = "0.4.22"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fbdf9cb251732db30a7200ebb6ae5d22fe8e11397364416617d2c2cf0c51cb5"
checksum = "4a6ecab92657eb234bfe98abd0b17920772c6b14ce69256950142e2eb36d000b"
dependencies = [
"malachite-base",
"malachite-nz",
@@ -1181,9 +1181,9 @@ dependencies = [
[[package]]
name = "malachite-base"
version = "0.4.22"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea0ed76adf7defc1a92240b5c36d5368cfe9251640dcce5bd2d0b7c1fd87aeb"
checksum = "06f6d078bb4dad5b76f6a85737e6c9113667d199612a73eef375c56e75d5d4d5"
dependencies = [
"hashbrown",
"itertools 0.11.0",
@@ -1193,9 +1193,9 @@ dependencies = [
[[package]]
name = "malachite-bigint"
version = "0.2.3"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d149aaa2965d70381709d9df4c7ee1fc0de1c614a4efc2ee356f5e43d68749f8"
checksum = "63c7698e7abae9522edd41b54ae0395a9bd736ca5054b5fbe672316283a7b817"
dependencies = [
"derive_more",
"malachite",
@@ -1206,9 +1206,9 @@ dependencies = [
[[package]]
name = "malachite-nz"
version = "0.4.22"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34a79feebb2bc9aa7762047c8e5495269a367da6b5a90a99882a0aeeac1841f7"
checksum = "ad61a09cde72dcdb8b2baaf3e71430c5bd94fb6753da89f17301a459f3e466db"
dependencies = [
"itertools 0.11.0",
"libm",
@@ -1217,9 +1217,9 @@ dependencies = [
[[package]]
name = "malachite-q"
version = "0.4.22"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f235d5747b1256b47620f5640c2a17a88c7569eebdf27cd9cb130e1a619191"
checksum = "be4a9dfffb87667ae94e8320213d3f5419e3e37311bc6bf8f4d2ab9b44f3a535"
dependencies = [
"itertools 0.11.0",
"malachite-base",
@@ -1897,7 +1897,7 @@ dependencies = [
[[package]]
name = "rustpython-ast"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"is-macro",
"malachite-bigint",
@@ -2009,7 +2009,7 @@ dependencies = [
[[package]]
name = "rustpython-format"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"bitflags 2.6.0",
"itertools 0.11.0",
@@ -2036,7 +2036,7 @@ dependencies = [
[[package]]
name = "rustpython-literal"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"hexf-parse",
"is-macro",
@@ -2048,7 +2048,7 @@ dependencies = [
[[package]]
name = "rustpython-parser"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"anyhow",
"is-macro",
@@ -2071,7 +2071,7 @@ dependencies = [
[[package]]
name = "rustpython-parser-core"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"is-macro",
"memchr",
@@ -2081,7 +2081,7 @@ dependencies = [
[[package]]
name = "rustpython-parser-vendored"
version = "0.4.0"
source = "git+https://github.com/RustPython/Parser.git?rev=d2f137b372ec08ce4a243564a80f8f9153c45a23#d2f137b372ec08ce4a243564a80f8f9153c45a23"
source = "git+https://github.com/RustPython/Parser.git?rev=4588ea5c3e6327009640e7c9c89eb6fa9220358e#4588ea5c3e6327009640e7c9c89eb6fa9220358e"
dependencies = [
"memchr",
"once_cell",

View File

@@ -127,11 +127,11 @@ rustpython-doc = { git = "https://github.com/RustPython/__doc__", tag = "0.3.0",
# rustpython-parser = { version = "0.4.0" }
# rustpython-ast = { version = "0.4.0" }
# rustpython-format= { version = "0.4.0" }
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "d2f137b372ec08ce4a243564a80f8f9153c45a23" }
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "d2f137b372ec08ce4a243564a80f8f9153c45a23" }
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "d2f137b372ec08ce4a243564a80f8f9153c45a23" }
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "d2f137b372ec08ce4a243564a80f8f9153c45a23" }
rustpython-format = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "d2f137b372ec08ce4a243564a80f8f9153c45a23" }
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "4588ea5c3e6327009640e7c9c89eb6fa9220358e" }
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "4588ea5c3e6327009640e7c9c89eb6fa9220358e" }
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "4588ea5c3e6327009640e7c9c89eb6fa9220358e" }
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "4588ea5c3e6327009640e7c9c89eb6fa9220358e" }
rustpython-format = { git = "https://github.com/RustPython/Parser.git", version = "0.4.0", rev = "4588ea5c3e6327009640e7c9c89eb6fa9220358e" }
# rustpython-literal = { path = "../RustPython-parser/literal" }
# rustpython-parser-core = { path = "../RustPython-parser/core" }
# rustpython-parser = { path = "../RustPython-parser/parser" }
@@ -157,9 +157,9 @@ junction = "1.0.0"
libc = "0.2.153"
log = "0.4.16"
nix = { version = "0.29", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
malachite-bigint = "0.2.3"
malachite-q = "0.4.22"
malachite-base = "0.4.22"
malachite-bigint = "0.2.2"
malachite-q = "<=0.4.18"
malachite-base = "<=0.4.18"
memchr = "2.7.2"
num-complex = "0.4.0"
num-integer = "0.1.44"

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<()> {
obj.set_dict(dict)
.map_err(|_| vm.new_attribute_error("This object has no __dict__".to_owned()))
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)) {