Skip to content

Commit b93636e

Browse files
authored
chore(deps): bump pyo3 0.20.3 -> 0.21.2 (#241)
* chore(deps): bump pyo3 0.20.3 -> 0.21.2 Signed-off-by: Luka Peschke <[email protected]> * fix compilation errors Signed-off-by: Luka Peschke <[email protected]> * fix deprecation warnings Signed-off-by: Luka Peschke <[email protected]> * convert FromPyObject impls to new bounds API Signed-off-by: Luka Peschke <[email protected]> --------- Signed-off-by: Luka Peschke <[email protected]>
1 parent 2147bb5 commit b93636e

File tree

8 files changed

+118
-99
lines changed

8 files changed

+118
-99
lines changed

Cargo.lock

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ crate-type = ["cdylib"]
1212
calamine = { version = "0.25.0", features = ["dates"] }
1313
chrono = { version = "0.4.38", default-features = false }
1414
# NOTE: "extension-module" is actually required, see comments on features below
15-
pyo3 = { version = "0.20.3", features = ["abi3-py38"] }
15+
pyo3 = { version = "0.21.2", features = ["abi3-py38"] }
1616

1717
[dependencies.arrow]
18-
version = "51.0.0"
18+
version = "52.0.0"
1919
# There's a lot of stuff we don't want here, such as serde support
2020
default-features = false
2121
features = ["pyarrow"]

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["maturin>=1.3.2,<2.0"]
2+
requires = ["maturin>=1.6.0,<2.0"]
33
build-backend = "maturin"
44

55
[project]
@@ -25,6 +25,7 @@ Issues = "https://github.com/ToucanToco/fastexcel"
2525
[tool.maturin]
2626
python-source = "python"
2727
module-name = "fastexcel._fastexcel"
28+
features = ["pyo3/extension-module"]
2829

2930
[tool.mypy]
3031
python_version = "3.8"

src/lib.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ mod types;
33
mod utils;
44

55
use error::{py_errors, ErrorContext};
6-
use pyo3::prelude::*;
6+
use pyo3::{prelude::*, types::PyString};
77
use types::python::{excelsheet::column_info::ColumnInfo, ExcelReader, ExcelSheet};
88

99
/// Reads an excel file and returns an object allowing to access its sheets and a bit of metadata
1010
#[pyfunction]
11-
fn read_excel(source: &PyAny) -> PyResult<ExcelReader> {
11+
fn read_excel(source: &Bound<'_, PyAny>) -> PyResult<ExcelReader> {
1212
use py_errors::IntoPyResult;
1313

14-
if let Ok(path) = source.extract::<&str>() {
14+
if let Ok(path) = source.extract::<&PyString>() {
15+
let path = path.to_str()?;
1516
ExcelReader::try_from_path(path)
1617
.with_context(|| format!("could not load excel file at {path}"))
1718
.into_pyresult()
@@ -39,7 +40,8 @@ fn get_version() -> String {
3940
}
4041

4142
#[pymodule]
42-
fn _fastexcel(py: Python, m: &PyModule) -> PyResult<()> {
43+
fn _fastexcel(m: &Bound<'_, PyModule>) -> PyResult<()> {
44+
let py = m.py();
4345
m.add_function(wrap_pyfunction!(read_excel, m)?)?;
4446
m.add_class::<ColumnInfo>()?;
4547
m.add_class::<ExcelSheet>()?;
@@ -48,32 +50,38 @@ fn _fastexcel(py: Python, m: &PyModule) -> PyResult<()> {
4850

4951
// errors
5052
[
51-
("FastExcelError", py.get_type::<py_errors::FastExcelError>()),
53+
(
54+
"FastExcelError",
55+
py.get_type_bound::<py_errors::FastExcelError>(),
56+
),
5257
(
5358
"UnsupportedColumnTypeCombinationError",
54-
py.get_type::<py_errors::UnsupportedColumnTypeCombinationError>(),
59+
py.get_type_bound::<py_errors::UnsupportedColumnTypeCombinationError>(),
5560
),
5661
(
5762
"CannotRetrieveCellDataError",
58-
py.get_type::<py_errors::CannotRetrieveCellDataError>(),
63+
py.get_type_bound::<py_errors::CannotRetrieveCellDataError>(),
5964
),
6065
(
6166
"CalamineCellError",
62-
py.get_type::<py_errors::CalamineCellError>(),
67+
py.get_type_bound::<py_errors::CalamineCellError>(),
68+
),
69+
(
70+
"CalamineError",
71+
py.get_type_bound::<py_errors::CalamineError>(),
6372
),
64-
("CalamineError", py.get_type::<py_errors::CalamineError>()),
6573
(
6674
"SheetNotFoundError",
67-
py.get_type::<py_errors::SheetNotFoundError>(),
75+
py.get_type_bound::<py_errors::SheetNotFoundError>(),
6876
),
6977
(
7078
"ColumnNotFoundError",
71-
py.get_type::<py_errors::ColumnNotFoundError>(),
79+
py.get_type_bound::<py_errors::ColumnNotFoundError>(),
7280
),
73-
("ArrowError", py.get_type::<py_errors::ArrowError>()),
81+
("ArrowError", py.get_type_bound::<py_errors::ArrowError>()),
7482
(
7583
"InvalidParametersError",
76-
py.get_type::<py_errors::InvalidParametersError>(),
84+
py.get_type_bound::<py_errors::InvalidParametersError>(),
7785
),
7886
]
7987
.into_iter()

src/types/dtype.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77

88
use arrow::datatypes::{DataType as ArrowDataType, TimeUnit};
99
use calamine::{CellErrorType, CellType, DataType, Range};
10-
use pyo3::{FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject};
10+
use pyo3::{
11+
prelude::PyAnyMethods, types::PyString, Bound, FromPyObject, PyAny, PyObject, PyResult, Python,
12+
ToPyObject,
13+
};
1114

1215
use crate::error::{py_errors::IntoPyResult, FastExcelError, FastExcelErrorKind, FastExcelResult};
1316

@@ -68,9 +71,9 @@ impl ToPyObject for DType {
6871
}
6972

7073
impl FromPyObject<'_> for DType {
71-
fn extract(py_dtype: &PyAny) -> PyResult<Self> {
72-
if let Ok(dtype_str) = py_dtype.extract::<&str>() {
73-
dtype_str.parse()
74+
fn extract_bound(py_dtype: &Bound<'_, PyAny>) -> PyResult<Self> {
75+
if let Ok(dtype_pystr) = py_dtype.extract::<&PyString>() {
76+
dtype_pystr.to_str()?.parse()
7477
} else {
7578
Err(FastExcelErrorKind::InvalidParameters(format!(
7679
"{py_dtype:?} cannot be converted to str"

src/types/idx_or_name.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use pyo3::{FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject};
1+
use pyo3::{
2+
prelude::PyAnyMethods, Bound, FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject,
3+
};
24

35
use crate::error::{py_errors::IntoPyResult, FastExcelError, FastExcelErrorKind, FastExcelResult};
46

@@ -17,10 +19,10 @@ impl IdxOrName {
1719
}
1820
}
1921

20-
impl TryFrom<&PyAny> for IdxOrName {
22+
impl TryFrom<&Bound<'_, PyAny>> for IdxOrName {
2123
type Error = FastExcelError;
2224

23-
fn try_from(value: &PyAny) -> FastExcelResult<Self> {
25+
fn try_from(value: &Bound<'_, PyAny>) -> FastExcelResult<Self> {
2426
if let Ok(index) = value.extract() {
2527
Ok(Self::Idx(index))
2628
} else if let Ok(name) = value.extract() {
@@ -35,8 +37,8 @@ impl TryFrom<&PyAny> for IdxOrName {
3537
}
3638

3739
impl FromPyObject<'_> for IdxOrName {
38-
fn extract(value: &PyAny) -> PyResult<Self> {
39-
value.try_into().into_pyresult()
40+
fn extract_bound(ob: &Bound<'_, PyAny>) -> PyResult<Self> {
41+
ob.try_into().into_pyresult()
4042
}
4143
}
4244

0 commit comments

Comments
 (0)