Skip to content

Commit

Permalink
py_new but I forgot I used __new__ some places which I kinda like....
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Dec 18, 2024
1 parent 0036b93 commit bc7f1e3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/ryo3-fnv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct PyFnvHasher {
impl PyFnvHasher {
#[new]
#[pyo3(signature = (s = None))]
fn new(s: Option<&[u8]>) -> Self {
fn py_new(s: Option<&[u8]>) -> Self {
match s {
Some(s) => {
let mut hasher = fnv_rs::FnvHasher::default();
Expand Down Expand Up @@ -63,7 +63,7 @@ impl PyFnvHasher {

#[pyfunction]
pub fn fnv1a(s: &[u8]) -> PyResult<PyFnvHasher> {
Ok(PyFnvHasher::new(Some(s)))
Ok(PyFnvHasher::py_new(Some(s)))
}

pub fn pymod_add(m: &Bound<'_, PyModule>) -> PyResult<()> {
Expand Down
8 changes: 4 additions & 4 deletions crates/ryo3-sqlformat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct PySqlfmtQueryParams {
#[pymethods]
impl PySqlfmtQueryParams {
#[new]
fn new(params: PyQueryParamsLike) -> PyResult<Self> {
fn py_new(params: PyQueryParamsLike) -> PyResult<Self> {
sqlfmt_params(Some(params))
}

Expand Down Expand Up @@ -134,11 +134,11 @@ pub fn sqlfmt_params(params: Option<PyQueryParamsLike>) -> PyResult<PySqlfmtQuer
}
}

#[pyfunction]
#[pyo3(signature = (sql, params=None, *, indent=None, uppercase=None, lines_between_queries=None))]
/// Format SQL queries
///
/// Based on [sqlformat-crate](https://crates.io/crates/sqlformat)
#[pyfunction]
#[pyo3(signature = (sql, params=None, *, indent=None, uppercase=None, lines_between_queries=None))]
pub fn sqlfmt(
sql: &str,
params: Option<PyQueryParamsLike>,
Expand All @@ -164,7 +164,7 @@ pub fn sqlfmt(
if let PyQueryParamsLike::PyQueryParams(p) = p {
Ok(sqlformat::format(sql, &p.params, &options))
} else {
let py_params = PySqlfmtQueryParams::new(p)?;
let py_params = PySqlfmtQueryParams::py_new(p)?;
Ok(sqlformat::format(sql, &py_params.params, &options))
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/ryo3-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct PyUrl(pub(crate) url::Url);
impl PyUrl {
#[new]
#[pyo3(signature = (url, *, params = None))]
fn new(url: &str, params: Option<&Bound<'_, PyDict>>) -> PyResult<Self> {
fn py_new(url: &str, params: Option<&Bound<'_, PyDict>>) -> PyResult<Self> {
if let Some(params) = params {
let params = params
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions crates/ryo3-xxhash/src/xxhashers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct PyXxh32 {
impl PyXxh32 {
#[new]
#[pyo3(signature = (b = None, seed = None))]
fn new(b: Option<&[u8]>, seed: Option<u32>) -> Self {
fn py_new(b: Option<&[u8]>, seed: Option<u32>) -> Self {
match b {
Some(s) => {
let seed = seed.unwrap_or(0);
Expand Down Expand Up @@ -83,7 +83,7 @@ impl PyXxh32 {
#[pyfunction]
#[pyo3(signature = (s = None, seed = 0))]
pub fn xxh32(s: Option<&[u8]>, seed: Option<u32>) -> PyResult<PyXxh32> {
Ok(PyXxh32::new(s, seed))
Ok(PyXxh32::py_new(s, seed))
}

/// Python-Xxh64 hasher
Expand All @@ -98,7 +98,7 @@ impl PyXxh64 {
/// Create a new Xxh64 hasher
#[new]
#[pyo3(signature = (b = None, seed = 0))]
fn new(b: Option<&[u8]>, seed: Option<u64>) -> Self {
fn py_new(b: Option<&[u8]>, seed: Option<u64>) -> Self {
match b {
Some(s) => {
let mut hasher = Xxh64::new(seed.unwrap_or(0));
Expand Down Expand Up @@ -168,7 +168,7 @@ impl PyXxh64 {
#[pyfunction]
#[pyo3(signature = (s = None, seed = 0))]
pub fn xxh64(s: Option<&[u8]>, seed: Option<u64>) -> PyResult<PyXxh64> {
Ok(PyXxh64::new(s, seed))
Ok(PyXxh64::py_new(s, seed))
}

#[pyclass(name = "Xxh3", module = "ryo3")]
Expand All @@ -181,7 +181,7 @@ pub struct PyXxh3 {
impl PyXxh3 {
#[new]
#[pyo3(signature = (b = None, seed = 0, secret = None))]
fn new(b: Option<&[u8]>, seed: Option<u64>, secret: Option<[u8; 192]>) -> Self {
fn py_new(b: Option<&[u8]>, seed: Option<u64>, secret: Option<[u8; 192]>) -> Self {
let seed = seed.unwrap_or(0);
let h = match secret {
Some(s) => Xxh3Builder::new().with_seed(seed).with_secret(s).build(),
Expand Down Expand Up @@ -262,7 +262,7 @@ impl PyXxh3 {
#[pyfunction]
#[pyo3(signature = (s = None, seed = 0, secret = None))]
pub fn xxh3(s: Option<&[u8]>, seed: Option<u64>, secret: Option<[u8; 192]>) -> PyResult<PyXxh3> {
Ok(PyXxh3::new(s, seed, secret))
Ok(PyXxh3::py_new(s, seed, secret))
}

pub fn pymod_add(m: &Bound<'_, PyModule>) -> PyResult<()> {
Expand Down
6 changes: 4 additions & 2 deletions crates/ryo3/src/fs/fspath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,10 @@ impl PyFsPath {
self.pth.ends_with(path.as_ref())
}

fn exists(&self) -> bool {
self.pth.exists()
fn exists(&self) -> PyResult<bool> {
self.pth
.try_exists()
.map_err(|e| PyFileNotFoundError::new_err(format!("(try_)exists: {e}")))
}

fn extension(&self) -> Option<String> {
Expand Down

0 comments on commit bc7f1e3

Please sign in to comment.