-
Notifications
You must be signed in to change notification settings - Fork 1.4k
disallow __new__, __init__ #6446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1540,7 +1540,7 @@ mod _sqlite { | |
| size: Option<c_int>, | ||
| } | ||
|
|
||
| #[pyclass(with(Constructor, IterNext, Iterable), flags(BASETYPE))] | ||
| #[pyclass(with(Constructor, Initializer, IterNext, Iterable), flags(BASETYPE))] | ||
| impl Cursor { | ||
| fn new( | ||
| connection: PyRef<Connection>, | ||
|
|
@@ -1571,24 +1571,6 @@ mod _sqlite { | |
| } | ||
| } | ||
|
|
||
| #[pymethod] | ||
| fn __init__(&self, _connection: PyRef<Connection>, _vm: &VirtualMachine) -> PyResult<()> { | ||
| let mut guard = self.inner.lock(); | ||
| if guard.is_some() { | ||
| // Already initialized (e.g., from a call to super().__init__) | ||
| return Ok(()); | ||
| } | ||
| *guard = Some(CursorInner { | ||
| description: None, | ||
| row_cast_map: vec![], | ||
| lastrowid: -1, | ||
| rowcount: -1, | ||
| statement: None, | ||
| closed: false, | ||
| }); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn check_cursor_state(inner: Option<&CursorInner>, vm: &VirtualMachine) -> PyResult<()> { | ||
| match inner { | ||
| Some(inner) if inner.closed => Err(new_programming_error( | ||
|
|
@@ -1949,6 +1931,27 @@ mod _sqlite { | |
| } | ||
| } | ||
|
|
||
| impl Initializer for Cursor { | ||
| type Args = PyRef<Connection>; | ||
|
|
||
|
Comment on lines
+1934
to
+1936
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for the Cursor implementation in sqlite.rs and examine Constructor/Initializer patterns
cd crates/stdlib/src || exit 1
# Look at lines around 1923 and 1934-1936 for Constructor and Initializer
echo "=== Constructor for Cursor (around line 1923) ==="
sed -n '1920,1930p' sqlite.rs
echo ""
echo "=== Initializer for Cursor (around line 1934-1936) ==="
sed -n '1933,1950p' sqlite.rsRepository: RustPython/RustPython Length of output: 1095 🏁 Script executed: #!/bin/bash
# Check Connection class pattern
cd crates/stdlib/src || exit 1
echo "=== Connection class Constructor (around line 853-937) ==="
grep -n "impl Constructor for Connection" sqlite.rs -A 10
echo ""
echo "=== Connection class Initializer ==="
grep -n "impl Initializer for Connection" sqlite.rs -A 10
echo ""
echo "=== Search for other Constructor/Initializer patterns in stdlib ==="
find crates/stdlib/src -name "*.rs" -exec grep -l "impl Constructor\|impl Initializer" {} \; | head -5Repository: RustPython/RustPython Length of output: 1345 🏁 Script executed: #!/bin/bash
# Get correct path and search for ConnectArgs definition and other patterns
find . -name "sqlite.rs" | head -1
echo ""
echo "=== Search for ConnectArgs definition ==="
rg "struct ConnectArgs|type ConnectArgs" crates/stdlib/src/sqlite.rs
echo ""
echo "=== Search for other Constructor/Initializer in sqlite.rs ==="
rg "impl Constructor|impl Initializer" crates/stdlib/src/sqlite.rs -B 1 -A 5
echo ""
echo "=== Search for Constructor/Initializer patterns across stdlib ==="
rg "impl Constructor|impl Initializer" . -t rs --max-count=20Repository: RustPython/RustPython Length of output: 1448 🏁 Script executed: #!/bin/bash
# Search for Constructor/Initializer patterns across the codebase
echo "=== Constructor/Initializer patterns in codebase ==="
rg "impl Constructor|impl Initializer" --max-count=30 -A 3
echo ""
echo "=== Row class implementation ==="
rg "impl Constructor for Row" crates/stdlib/src/sqlite.rs -A 10
echo ""
echo "=== Check if Row has Initializer ==="
rg "impl Initializer for Row" crates/stdlib/src/sqlite.rs -A 5Repository: RustPython/RustPython Length of output: 39811 🏁 Script executed: #!/bin/bash
# Check how Constructor and Initializer are invoked in the framework
echo "=== Look for how Constructor and Initializer are called ==="
rg "impl.*Constructor\|impl.*Initializer" crates/vm/src/object/ -A 20 | head -100
echo ""
echo "=== Check if there's framework code handling argument conversion ==="
rg "fn py_new|fn init" crates/vm/src/object/ -B 2 -A 5 | head -80Repository: RustPython/RustPython Length of output: 688 🏁 Script executed: #!/bin/bash
# Search for Constructor and Initializer trait definitions
echo "=== Constructor trait definition ==="
rg "trait Constructor" crates/vm/src/ -A 10
echo ""
echo "=== Initializer trait definition ==="
rg "trait Initializer" crates/vm/src/ -A 10
echo ""
echo "=== Look for code that calls Constructor::py_new and Initializer::init ==="
rg "Constructor::py_new|Initializer::init" crates/vm/src/ -B 2 -A 2 | head -60Repository: RustPython/RustPython Length of output: 2361 🏁 Script executed: #!/bin/bash
# Look at the full slot_init implementation
echo "=== Full Initializer::slot_init implementation ==="
rg "fn slot_init" crates/vm/src/types/slot.rs -A 25
echo ""
echo "=== Check FromArgs trait ==="
rg "trait FromArgs" crates/vm/src/ -A 5Repository: RustPython/RustPython Length of output: 1640 🏁 Script executed: #!/bin/bash
# Verify if Row has Initializer by doing a more thorough search
echo "=== Search for Row impl blocks in sqlite.rs ==="
rg "impl.*for Row" crates/stdlib/src/sqlite.rs -A 3
echo ""
echo "=== Check the line numbers for Row to understand its structure ==="
rg -n "^struct Row" crates/stdlib/src/sqlite.rs
echo ""
echo "=== Look for all impl blocks after Row struct ==="
rg -n "impl.*Row" crates/stdlib/src/sqlite.rsRepository: RustPython/RustPython Length of output: 1480 🏁 Script executed: #!/bin/bash
# Check if there's automatic FromArgs handling for tuples vs non-tuples
echo "=== Search for FromArgs implementation for tuples ==="
rg "impl.*FromArgs.*for.*\(" crates/vm/src/function/ -A 5 | head -80
echo ""
echo "=== Check if there are FromArgs implementations handling conversion ==="
rg "impl.*FromArgs" crates/vm/src/function/argument.rs -A 8 | head -120Repository: RustPython/RustPython Length of output: 3127 🏁 Script executed: #!/bin/bash
# Look at the actual tuple FromArgs implementation more carefully
echo "=== Full tuple_from_py_func_args macro ==="
rg "tuple_from_py_func_args" crates/vm/src/function/argument.rs -A 50 | head -150
echo ""
echo "=== Test if single-element tuple behaves same as non-tuple ==="
echo "Looking for how args.bind works..."
rg "fn bind\|pub fn bind" crates/vm/src/ -B 2 -A 8 | head -80Repository: RustPython/RustPython Length of output: 1422 🏁 Script executed: #!/bin/bash
# Verify the actual framework behavior - let's check if there are any tests for Cursor
echo "=== Check for Cursor tests to understand expected behavior ==="
find . -name "*.rs" -path "*/tests/*" -o -name "*test*" | xargs grep -l "Cursor\|sqlite" 2>/dev/null | head -5
echo ""
echo "=== Check if there's documentation about how Constructor and Initializer Args should relate ==="
rg "Constructor.*Args|Initializer.*Args" crates/vm/src/types/slot.rs -B 3 -A 3
echo ""
echo "=== Final confirmation: check the exact parameter handling in init function ==="
sed -n '1936,1945p' crates/stdlib/src/sqlite.rsRepository: RustPython/RustPython Length of output: 723 Argument type inconsistency between Constructor and Initializer. The While the RustPython framework's 🤖 Prompt for AI Agents |
||
| fn init(zelf: PyRef<Self>, _connection: Self::Args, _vm: &VirtualMachine) -> PyResult<()> { | ||
| let mut guard = zelf.inner.lock(); | ||
| if guard.is_some() { | ||
| // Already initialized (e.g., from a call to super().__init__) | ||
| return Ok(()); | ||
| } | ||
| *guard = Some(CursorInner { | ||
| description: None, | ||
| row_cast_map: vec![], | ||
| lastrowid: -1, | ||
| rowcount: -1, | ||
| statement: None, | ||
| closed: false, | ||
| }); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl SelfIter for Cursor {} | ||
| impl IterNext for Cursor { | ||
| fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.