Skip to content
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

PyEllipsis type #2906

Closed
samuelcolvin opened this issue Jan 24, 2023 · 2 comments · Fixed by #2911
Closed

PyEllipsis type #2906

samuelcolvin opened this issue Jan 24, 2023 · 2 comments · Fixed by #2911

Comments

@samuelcolvin
Copy link
Contributor

Would be great to have an Ellipsis type, aka ... in python.

The ffi type seems to exist

pub unsafe fn Py_Ellipsis() -> *mut PyObject {
addr_of_mut_shim!(_Py_EllipsisObject)
}

But I'm not sure how I would use it in safe rust code.

@mejrs
Copy link
Member

mejrs commented Jan 24, 2023

We can make a method for that just like None and NotImplemented : https://docs.rs/pyo3/latest/pyo3/marker/struct.Python.html#method.None

If you want it in safe rust right now, I think you'd need to get the builtins module, and then getattr the ellipsis object.

@samuelcolvin
Copy link
Contributor Author

Thanks that would be great, that's what I was using, but your comment lead me to what I really needed which was simply

fn is_ellipsis(v: &PyAny) -> bool {
    unsafe { v.as_ptr() == Py_Ellipsis() }
}

Might be worth adding is_ellipsis as well like is_none?

samuelcolvin added a commit to samuelcolvin/pyo3 that referenced this issue Jan 25, 2023
samuelcolvin added a commit to samuelcolvin/pyo3 that referenced this issue Jan 25, 2023
samuelcolvin added a commit to samuelcolvin/pyo3 that referenced this issue Jan 25, 2023
bors bot added a commit that referenced this issue Jan 27, 2023
2911: add `Ellipsis()` and `is_ellipsis()` methods r=mejrs,davidhewitt a=samuelcolvin

fix #2906

Please consider adding the following to your pull request:
 - [x] an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
 - [x] docs to all new functions and / or detail in the guide
 - [x] tests for all new or changed functions


Co-authored-by: Samuel Colvin <s@muelcolvin.com>
@bors bors bot closed this as completed in 3c9ace0 Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants