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

add Ellipsis() and is_ellipsis() methods #2911

Merged
merged 1 commit into from
Jan 27, 2023
Merged

Conversation

samuelcolvin
Copy link
Contributor

fix #2906

Please consider adding the following to your pull request:

  • an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
  • docs to all new functions and / or detail in the guide
  • tests for all new or changed functions

@samuelcolvin
Copy link
Contributor Author

Seems to really be failing on windows, error is

note: pyo3-8a1fda91fe8449f2.pyo3.3a3efd38-cgu.1.rcgu.o : error LNK2019: unresolved external symbol __Py_EllipsisObject referenced in function 

Any ideas?

@mejrs
Copy link
Member

mejrs commented Jan 25, 2023

Seems to really be failing on windows, error is

note: pyo3-8a1fda91fe8449f2.pyo3.3a3efd38-cgu.1.rcgu.o : error LNK2019: unresolved external symbol __Py_EllipsisObject referenced in function 

Any ideas?

I'm guessing it needs a #[cfg_attr(windows, link(name = "pythonXY"))] to link correctly. I can check tonight if you can't figure it out.

@samuelcolvin
Copy link
Contributor Author

I'm guessing it needs a #[cfg_attr(windows, link(name = "pythonXY"))] to link correctly. I can check tonight if you can't figure it out.

Ha, I'm trying exactly that having seen it here.

Copy link
Member

@mejrs mejrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

src/instance.rs Outdated Show resolved Hide resolved
@samuelcolvin
Copy link
Contributor Author

Would be great to get this merged and released as I'm currently having to get pyo3 from my branch due to the windows issue. 🚀 🏃

See pydantic/pydantic-core#370.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. My family's sick with a cold again....

I think there's some API details which I'd like to at least discuss whether we can do better before we merge.

/// Gets the Python builtin value `Ellipsis`, or `...`.
#[allow(non_snake_case)] // the Python keyword starts with uppercase
#[inline]
pub fn Ellipsis(self) -> PyObject {
Copy link
Member

@davidhewitt davidhewitt Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than returning PyObject here it would probably be nicer if we returned &PyEllipsis, and created a new struct types::PyEllipsis. (Would avoid the need to increase a reference count here.)

That would also mean that x.is_instance::<PyEllipsis>() would just work instead of needing is_ellipsis, which does have the upside of avoiding a special method. Not necessarily saying that it's better, perhaps is_ellipsis is still warranted.

Also, adding types::PyEllipsis would pave the way for instead just having PyEllipsis::get(py) to retrieve the singleton, rather than adding this to Python which I don't think really needs this method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should do this for None and NotImplemented too. The current pr mirrors their api.

Copy link
Member

@davidhewitt davidhewitt Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and I've been wanting to do that for a while. I guess we can't change those for 0.18.x, so perhaps we merge this as-is and I'll probably raise a follow-up PR to propose adjusting all three on the way to 0.19?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved as per comment that I'll try to find some time to add to this on the way to 0.19.

I've just force-pushed to squash-and-rebase, will merge. Thanks!

@davidhewitt
Copy link
Member

bors r=mejrs,davidhewitt

@bors
Copy link
Contributor

bors bot commented Jan 27, 2023

Build succeeded:

@bors bors bot merged commit 794e19d into PyO3:main Jan 27, 2023
@samuelcolvin samuelcolvin deleted the ellipsis branch January 31, 2023 12:22
@samuelcolvin samuelcolvin restored the ellipsis branch January 31, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PyEllipsis type
3 participants