[{"id":4164600978,"node_id":"PRR_kwDOCA8Bec74OsSS","user":{"login":"coderabbitai[bot]","id":136622811,"node_id":"BOT_kgDOCCSy2w","avatar_url":"https:\/\/avatars.githubusercontent.com\/in\/347564?v=4","gravatar_id":"","url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D","html_url":"https:\/\/github.com\/apps\/coderabbitai","followers_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/followers","following_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/following{\/other_user}","gists_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/starred{\/owner}{\/repo}","subscriptions_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/subscriptions","organizations_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/orgs","repos_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/repos","events_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/events{\/privacy}","received_events_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/received_events","type":"Bot","user_view_type":"public","site_admin":false},"body":"\n\n<details>\n<summary>\ud83e\uddf9 Nitpick comments (2)<\/summary><blockquote>\n\n<details>\n<summary>crates\/derive-impl\/src\/pyclass.rs (2)<\/summary><blockquote>\n\n`337-353`: **Named-field branch silently skips the assertion if `ident` is `None`.**\n\nFor `syn::Fields::Named`, `first_field.ident` is guaranteed to be `Some` by the parser, so `ident.as_ref().map(|id| quote! { `#id` })` returning `None` is unreachable in practice. Since the caller treats `Ok(None)` as \"no assertion to emit\", a logic bug here would silently disable the layout safety net instead of erroring. Consider `expect`\u2011ing the invariant or returning `Some` unconditionally so the guarantee is explicit:\n\n<details>\n<summary>\u267b\ufe0f Make the invariant explicit<\/summary>\n\n```diff\n-            let ident = first_field.ident.as_ref().map(|id| quote! { `#id` });\n-            Ok(ident)\n+            let ident = first_field\n+                .ident\n+                .as_ref()\n+                .expect(\"syn::Fields::Named always has field idents\");\n+            Ok(Some(quote! { `#ident` }))\n```\n<\/details>\n\n<details>\n<summary>\ud83e\udd16 Prompt for AI Agents<\/summary>\n\n```\nVerify each finding against the current code and only fix it if needed.\n\nIn `@crates\/derive-impl\/src\/pyclass.rs` around lines 337 - 353, In the named-field\nbranch of the match (handling syn::Fields::Named), the current mapping of\nfirst_field.ident to ident can produce Ok(None) which silently disables the\nassertion; make the parser invariant explicit by unwrapping\/expect-ing\nfirst_field.ident (e.g., use first_field.ident.as_ref().expect(...)) and return\nan owned Some(quote! { `#id` }) so the function returns Ok(Some(...)) instead of\nOk(None); this ensures the #[pyclass] base-type assertion (checked via\ntype_matches_path and first_field) cannot be bypassed silently.\n```\n\n<\/details>\n\n---\n\n`384-394`: **`ensure_repr_c` opts out on any `#[repr(...)]`, including ones that don't guarantee offset\u20110.**\n\n`has_repr` matches any `repr` attribute, so a user who writes only `#[repr(align(N))]` (or `#[repr(packed)]` without `C`) will not get `#[repr(C)]` auto\u2011inserted even though those reprs alone don't pin the base field to offset 0 under current Rust layout rules. In practice the `offset_of!` assertion emitted at lines 606\u2013619 catches this at compile time, so this is not a correctness gap \u2014 just worth being explicit about in the comment so future maintainers don't assume `ensure_repr_c` alone is sufficient.\n\nOptionally, you could narrow the opt\u2011out to reprs that already guarantee declaration order (`C`, `transparent`) and still layer the assert on top:\n\n<details>\n<summary>\u267b\ufe0f Narrower opt\u2011out<\/summary>\n\n```diff\n-    let has_repr = s.attrs.iter().any(|attr| attr.path().is_ident(\"repr\"));\n-    if !has_repr {\n+    \/\/ Only treat reprs that guarantee declaration order as an opt-out;\n+    \/\/ `align`\/`packed` alone do not pin the base field to offset 0.\n+    let has_layout_repr = s.attrs.iter().any(|attr| {\n+        if !attr.path().is_ident(\"repr\") {\n+            return false;\n+        }\n+        let mut found = false;\n+        let _ = attr.parse_nested_meta(|meta| {\n+            if meta.path.is_ident(\"C\") || meta.path.is_ident(\"transparent\") {\n+                found = true;\n+            }\n+            Ok(())\n+        });\n+        found\n+    });\n+    if !has_layout_repr {\n         let repr_c: syn::Attribute = parse_quote!(#[repr(C)]);\n         s.attrs.push(repr_c);\n     }\n```\n<\/details>\n\n<details>\n<summary>\ud83e\udd16 Prompt for AI Agents<\/summary>\n\n```\nVerify each finding against the current code and only fix it if needed.\n\nIn `@crates\/derive-impl\/src\/pyclass.rs` around lines 384 - 394, ensure_repr_c\ncurrently treats any #[repr(...)] as reason to skip adding #[repr(C)], which\nincorrectly skips structs that use #[repr(align(...))] or #[repr(packed)] that\ndon't guarantee declaration-order layout; update ensure_repr_c so it only opts\nout when an existing repr explicitly guarantees declaration order (i.e., path\nis_ident \"repr\" and contains \"C\" or \"transparent\"), otherwise push #[repr(C)] as\nbefore; also add a short clarifying comment in the ensure_repr_c function noting\nthat the offset_of! assertion elsewhere still protects against remaining cases.\n```\n\n<\/details>\n\n<\/blockquote><\/details>\n\n<\/blockquote><\/details>\n\n<details>\n<summary>\ud83e\udd16 Prompt for all review comments with AI agents<\/summary>\n\n```\nVerify each finding against the current code and only fix it if needed.\n\nNitpick comments:\nIn `@crates\/derive-impl\/src\/pyclass.rs`:\n- Around line 337-353: In the named-field branch of the match (handling\nsyn::Fields::Named), the current mapping of first_field.ident to ident can\nproduce Ok(None) which silently disables the assertion; make the parser\ninvariant explicit by unwrapping\/expect-ing first_field.ident (e.g., use\nfirst_field.ident.as_ref().expect(...)) and return an owned Some(quote! { `#id` })\nso the function returns Ok(Some(...)) instead of Ok(None); this ensures the\n#[pyclass] base-type assertion (checked via type_matches_path and first_field)\ncannot be bypassed silently.\n- Around line 384-394: ensure_repr_c currently treats any #[repr(...)] as reason\nto skip adding #[repr(C)], which incorrectly skips structs that use\n#[repr(align(...))] or #[repr(packed)] that don't guarantee declaration-order\nlayout; update ensure_repr_c so it only opts out when an existing repr\nexplicitly guarantees declaration order (i.e., path is_ident \"repr\" and contains\n\"C\" or \"transparent\"), otherwise push #[repr(C)] as before; also add a short\nclarifying comment in the ensure_repr_c function noting that the offset_of!\nassertion elsewhere still protects against remaining cases.\n```\n\n<\/details>\n\n---\n\n<details>\n<summary>\u2139\ufe0f Review info<\/summary>\n\n<details>\n<summary>\u2699\ufe0f Run configuration<\/summary>\n\n**Configuration used**: Path: .coderabbit.yml\n\n**Review profile**: CHILL\n\n**Plan**: Pro\n\n**Run ID**: `91b82e56-aea9-4877-885c-ff2bee16fcd8`\n\n<\/details>\n\n<details>\n<summary>\ud83d\udce5 Commits<\/summary>\n\nReviewing files that changed from the base of the PR and between 5081f76faf962abd1fce659a963fd81bf9172ccd and 48311be40777dd5207a623823ae031311b66b031.\n\n<\/details>\n\n<details>\n<summary>\ud83d\udcd2 Files selected for processing (3)<\/summary>\n\n* `crates\/derive-impl\/src\/pyclass.rs`\n* `crates\/stdlib\/src\/_asyncio.rs`\n* `crates\/vm\/src\/builtins\/builtin_func.rs`\n\n<\/details>\n\n<details>\n<summary>\ud83d\udca4 Files with no reviewable changes (2)<\/summary>\n\n* crates\/vm\/src\/builtins\/builtin_func.rs\n* crates\/stdlib\/src\/_asyncio.rs\n\n<\/details>\n\n<\/details>\n\n<!-- This is an auto-generated comment by CodeRabbit for review status -->","state":"COMMENTED","html_url":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164600978","pull_request_url":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663","author_association":"CONTRIBUTOR","is_copilot_code_review":false,"copilot_code_review_effort":null,"_links":{"html":{"href":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164600978"},"pull_request":{"href":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663"}},"submitted_at":"2026-04-23T17:43:23Z","commit_id":"48311be40777dd5207a623823ae031311b66b031"},{"id":4164719512,"node_id":"PRR_kwDOCA8Bec74PJOY","user":{"login":"fanninpm","id":27117322,"node_id":"MDQ6VXNlcjI3MTE3MzIy","avatar_url":"https:\/\/avatars.githubusercontent.com\/u\/27117322?v=4","gravatar_id":"","url":"https:\/\/api.github.com\/users\/fanninpm","html_url":"https:\/\/github.com\/fanninpm","followers_url":"https:\/\/api.github.com\/users\/fanninpm\/followers","following_url":"https:\/\/api.github.com\/users\/fanninpm\/following{\/other_user}","gists_url":"https:\/\/api.github.com\/users\/fanninpm\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/fanninpm\/starred{\/owner}{\/repo}","subscriptions_url":"https:\/\/api.github.com\/users\/fanninpm\/subscriptions","organizations_url":"https:\/\/api.github.com\/users\/fanninpm\/orgs","repos_url":"https:\/\/api.github.com\/users\/fanninpm\/repos","events_url":"https:\/\/api.github.com\/users\/fanninpm\/events{\/privacy}","received_events_url":"https:\/\/api.github.com\/users\/fanninpm\/received_events","type":"User","user_view_type":"public","site_admin":false},"body":"","state":"COMMENTED","html_url":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164719512","pull_request_url":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663","author_association":"CONTRIBUTOR","is_copilot_code_review":false,"copilot_code_review_effort":null,"_links":{"html":{"href":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164719512"},"pull_request":{"href":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663"}},"submitted_at":"2026-04-23T18:00:31Z","commit_id":"2980ad175b89b6c10818320242cb7b17559b1cb5"},{"id":4164730040,"node_id":"PRR_kwDOCA8Bec74PLy4","user":{"login":"coderabbitai[bot]","id":136622811,"node_id":"BOT_kgDOCCSy2w","avatar_url":"https:\/\/avatars.githubusercontent.com\/in\/347564?v=4","gravatar_id":"","url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D","html_url":"https:\/\/github.com\/apps\/coderabbitai","followers_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/followers","following_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/following{\/other_user}","gists_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/starred{\/owner}{\/repo}","subscriptions_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/subscriptions","organizations_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/orgs","repos_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/repos","events_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/events{\/privacy}","received_events_url":"https:\/\/api.github.com\/users\/coderabbitai%5Bbot%5D\/received_events","type":"Bot","user_view_type":"public","site_admin":false},"body":"\n\n<details>\n<summary>\ud83e\uddf9 Nitpick comments (1)<\/summary><blockquote>\n\n<details>\n<summary>crates\/derive-impl\/src\/pyclass.rs (1)<\/summary><blockquote>\n\n`378-394`: **Auto-inserted `#[repr(C)]` + compile-time `offset_of!` assertion is a solid two-layer defense.**\n\nThe combination of (a) defaulting bare `#[pyclass]` derived structs to `#[repr(C)]` and (b) emitting a `const _: ()` `offset_of!` assertion for any struct that already carries an explicit repr is a good belt-and-suspenders approach: the common case gets a correct layout for free, and the pathological case fails at compile time instead of segfaulting at runtime.\n\nOne minor nit on the diagnostic text in the const assert (Lines 617-621): `#[repr(transparent)]` is only valid for structs with a single non-ZST field, so suggesting it alongside `#[repr(C)]` as an equally-good fix could mislead users of multi-field derived classes (which is exactly the case the PR is motivated by). Consider softening the suggestion, e.g. \"Add `#[repr(C)]` (or remove the explicit repr so the macro inserts it)\".\n\n<details>\n<summary>\ud83e\udd16 Prompt for AI Agents<\/summary>\n\n```\nVerify each finding against the current code and only fix it if needed.\n\nIn `@crates\/derive-impl\/src\/pyclass.rs` around lines 378 - 394, Update the\ndiagnostic text emitted alongside the compile-time `offset_of!` assertion so it\ndoes not suggest `#[repr(transparent)]` as an equally-valid fix for multi-field\nstructs; instead soften the suggestion to something like \"Add `#[repr(C)]` (or\nremove the explicit repr so the macro inserts it)\". Locate the code that\ngenerates the `const _: ()` `offset_of!` assertion (the code that builds the\ndiagnostic string next to the `offset_of!` check for explicit reprs \u2014 referenced\nin this diff as the assertion emitted when an explicit repr is present) and\nreplace the message text accordingly; keep the rest of the assertion logic\nintact.\n```\n\n<\/details>\n\n<\/blockquote><\/details>\n\n<\/blockquote><\/details>\n\n<details>\n<summary>\ud83e\udd16 Prompt for all review comments with AI agents<\/summary>\n\n```\nVerify each finding against the current code and only fix it if needed.\n\nNitpick comments:\nIn `@crates\/derive-impl\/src\/pyclass.rs`:\n- Around line 378-394: Update the diagnostic text emitted alongside the\ncompile-time `offset_of!` assertion so it does not suggest\n`#[repr(transparent)]` as an equally-valid fix for multi-field structs; instead\nsoften the suggestion to something like \"Add `#[repr(C)]` (or remove the\nexplicit repr so the macro inserts it)\". Locate the code that generates the\n`const _: ()` `offset_of!` assertion (the code that builds the diagnostic string\nnext to the `offset_of!` check for explicit reprs \u2014 referenced in this diff as\nthe assertion emitted when an explicit repr is present) and replace the message\ntext accordingly; keep the rest of the assertion logic intact.\n```\n\n<\/details>\n\n---\n\n<details>\n<summary>\u2139\ufe0f Review info<\/summary>\n\n<details>\n<summary>\u2699\ufe0f Run configuration<\/summary>\n\n**Configuration used**: Path: .coderabbit.yml\n\n**Review profile**: CHILL\n\n**Plan**: Pro\n\n**Run ID**: `0b5c333e-4a4f-47d8-aea0-aa944364fdf4`\n\n<\/details>\n\n<details>\n<summary>\ud83d\udce5 Commits<\/summary>\n\nReviewing files that changed from the base of the PR and between 48311be40777dd5207a623823ae031311b66b031 and 2980ad175b89b6c10818320242cb7b17559b1cb5.\n\n<\/details>\n\n<details>\n<summary>\ud83d\udcd2 Files selected for processing (1)<\/summary>\n\n* `crates\/derive-impl\/src\/pyclass.rs`\n\n<\/details>\n\n<\/details>\n\n<!-- This is an auto-generated comment by CodeRabbit for review status -->","state":"COMMENTED","html_url":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164730040","pull_request_url":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663","author_association":"CONTRIBUTOR","is_copilot_code_review":false,"copilot_code_review_effort":null,"_links":{"html":{"href":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4164730040"},"pull_request":{"href":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663"}},"submitted_at":"2026-04-23T18:01:59Z","commit_id":"2980ad175b89b6c10818320242cb7b17559b1cb5"},{"id":4168801802,"node_id":"PRR_kwDOCA8Bec74et4K","user":{"login":"youknowone","id":69878,"node_id":"MDQ6VXNlcjY5ODc4","avatar_url":"https:\/\/avatars.githubusercontent.com\/u\/69878?v=4","gravatar_id":"","url":"https:\/\/api.github.com\/users\/youknowone","html_url":"https:\/\/github.com\/youknowone","followers_url":"https:\/\/api.github.com\/users\/youknowone\/followers","following_url":"https:\/\/api.github.com\/users\/youknowone\/following{\/other_user}","gists_url":"https:\/\/api.github.com\/users\/youknowone\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/youknowone\/starred{\/owner}{\/repo}","subscriptions_url":"https:\/\/api.github.com\/users\/youknowone\/subscriptions","organizations_url":"https:\/\/api.github.com\/users\/youknowone\/orgs","repos_url":"https:\/\/api.github.com\/users\/youknowone\/repos","events_url":"https:\/\/api.github.com\/users\/youknowone\/events{\/privacy}","received_events_url":"https:\/\/api.github.com\/users\/youknowone\/received_events","type":"User","user_view_type":"public","site_admin":false},"body":"I have a question about the current situation. As I understand it, `#[repr(C)]` is only required for types that have derived implementations. Is that correct?\nIf even base types without any derived implementations also require `#[repr(C)]`, then I would agree with this patch. Otherwise, I would prefer to keep `#[repr(C)]` explicit, and rather than having the macro automatically add `#[repr(C)]`, I would prefer it to emit a warning when a base type is missing `#[repr(C)]`.","state":"COMMENTED","html_url":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4168801802","pull_request_url":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663","author_association":"MEMBER","is_copilot_code_review":false,"copilot_code_review_effort":null,"_links":{"html":{"href":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4168801802"},"pull_request":{"href":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663"}},"submitted_at":"2026-04-24T07:44:34Z","commit_id":"280ecd3955a95c06e56da3b2b5c9b27bf126ccb5"},{"id":4171238874,"node_id":"PRR_kwDOCA8Bec74oA3a","user":{"login":"youknowone","id":69878,"node_id":"MDQ6VXNlcjY5ODc4","avatar_url":"https:\/\/avatars.githubusercontent.com\/u\/69878?v=4","gravatar_id":"","url":"https:\/\/api.github.com\/users\/youknowone","html_url":"https:\/\/github.com\/youknowone","followers_url":"https:\/\/api.github.com\/users\/youknowone\/followers","following_url":"https:\/\/api.github.com\/users\/youknowone\/following{\/other_user}","gists_url":"https:\/\/api.github.com\/users\/youknowone\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/youknowone\/starred{\/owner}{\/repo}","subscriptions_url":"https:\/\/api.github.com\/users\/youknowone\/subscriptions","organizations_url":"https:\/\/api.github.com\/users\/youknowone\/orgs","repos_url":"https:\/\/api.github.com\/users\/youknowone\/repos","events_url":"https:\/\/api.github.com\/users\/youknowone\/events{\/privacy}","received_events_url":"https:\/\/api.github.com\/users\/youknowone\/received_events","type":"User","user_view_type":"public","site_admin":false},"body":"Thank you for the explanation. ","state":"APPROVED","html_url":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4171238874","pull_request_url":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663","author_association":"MEMBER","is_copilot_code_review":false,"copilot_code_review_effort":null,"_links":{"html":{"href":"https:\/\/github.com\/RustPython\/RustPython\/pull\/7663#pullrequestreview-4171238874"},"pull_request":{"href":"https:\/\/api.github.com\/repos\/RustPython\/RustPython\/pulls\/7663"}},"submitted_at":"2026-04-24T14:30:12Z","commit_id":"280ecd3955a95c06e56da3b2b5c9b27bf126ccb5"}]