-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The PyO3 API changes pretty dramatically, but we can use this opportunity to clean up a lot of the Python<->Rust interaction. The main pain is that `to_object` and `into_py` are now deprecated.
- Loading branch information
Showing
20 changed files
with
332 additions
and
456 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,35 @@ | ||
use pyo3::{ | ||
prelude::*, | ||
types::{PyList, PyString}, | ||
}; | ||
use pyo3::{prelude::*, types::PyFrozenSet}; | ||
|
||
use edgeql_parser::keywords; | ||
|
||
pub struct AllKeywords { | ||
pub current: PyObject, | ||
pub future: PyObject, | ||
pub unreserved: PyObject, | ||
pub partial: PyObject, | ||
pub current: Py<PyFrozenSet>, | ||
pub future: Py<PyFrozenSet>, | ||
pub unreserved: Py<PyFrozenSet>, | ||
pub partial: Py<PyFrozenSet>, | ||
} | ||
|
||
pub fn get_keywords(py: Python) -> PyResult<AllKeywords> { | ||
let intern = py.import_bound("sys")?.getattr("intern")?; | ||
let frozen = py.import_bound("builtins")?.getattr("frozenset")?; | ||
let intern = py.import("sys")?.getattr("intern")?; | ||
|
||
let current = prepare_keywords(py, keywords::CURRENT_RESERVED_KEYWORDS.iter(), &intern)?; | ||
let unreserved = prepare_keywords(py, keywords::UNRESERVED_KEYWORDS.iter(), &intern)?; | ||
let future = prepare_keywords(py, keywords::FUTURE_RESERVED_KEYWORDS.iter(), &intern)?; | ||
let partial = prepare_keywords(py, keywords::PARTIAL_RESERVED_KEYWORDS.iter(), &intern)?; | ||
Ok(AllKeywords { | ||
current: frozen | ||
.call((PyList::new_bound(py, ¤t),), None)? | ||
.into(), | ||
unreserved: frozen | ||
.call((PyList::new_bound(py, &unreserved),), None)? | ||
.into(), | ||
future: frozen.call((PyList::new_bound(py, &future),), None)?.into(), | ||
partial: frozen | ||
.call((PyList::new_bound(py, &partial),), None)? | ||
.into(), | ||
current: prepare_keywords(py, &keywords::CURRENT_RESERVED_KEYWORDS, &intern)?, | ||
unreserved: prepare_keywords(py, &keywords::UNRESERVED_KEYWORDS, &intern)?, | ||
future: prepare_keywords(py, &keywords::FUTURE_RESERVED_KEYWORDS, &intern)?, | ||
partial: prepare_keywords(py, &keywords::PARTIAL_RESERVED_KEYWORDS, &intern)?, | ||
}) | ||
} | ||
|
||
fn prepare_keywords<'py, I: Iterator<Item = &'py &'static str>>( | ||
fn prepare_keywords<'a, 'py, I: IntoIterator<Item = &'a &'static str>>( | ||
py: Python<'py>, | ||
keyword_set: I, | ||
intern: &'py Bound<'py, PyAny>, | ||
) -> Result<Vec<Bound<'py, PyAny>>, PyErr> { | ||
keyword_set | ||
.cloned() | ||
.map(|s: &str| intern.call((PyString::new_bound(py, s),), None)) | ||
.collect() | ||
intern: &Bound<'py, PyAny>, | ||
) -> PyResult<Py<PyFrozenSet>> { | ||
PyFrozenSet::new( | ||
py, | ||
keyword_set | ||
.into_iter() | ||
.map(|s| intern.call((&s,), None).unwrap()), | ||
) | ||
.map(|o| o.unbind()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.