-
Notifications
You must be signed in to change notification settings - Fork 760
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
Remove ObjectProtocol to make usage more Pythonic #892
Conversation
Thank you, but now I'm thinking about there can be a case we need |
👍 - IMHO (I guess these changes also affect |
FWIW I feel more strongly about the names like |
Regarding removing ObjectProtocol, I like the idea of having only one place where to look up all the available methods. About having |
That's a reasonable argument @Alexander-N 👍 Maybe here's another idea - what do you think if we supported both Then those like me who want to use these functions like in Python can write And also those like yourself who prefer the Rustic way can use I mostly agree with you there's an argument that "there should be only one obvious way" - but I think on this point the obvious way maybe differs if you're a Python user expecting to do |
I think as soon as several people work on one codebase there will be a cost in enabling inconsistencies which for me outweighs the benefit of having different APIs for different preferences. Also, I fear that this will cause confusion to new users, as to what's the difference between |
I think the idea here is that ObjectProtocol is just redundant since it would only be implemented for PyAny. So there's still only one place to look them up. |
Note that
|
Since it is quite hard to see at a glance: the difference is that |
Strange! I wonder if this is a CPython implementation detail, or is specified in docs. I'll have a dig 😄 |
Please wait for a bit...
OK. No problem except it can look odd to use
The only concern I had was it can be separated into
As a user, I don't want them. And as a maintainer, I haven't heard that any user complains about that(e.g., we have no issue like 'why PyO3 doesn't have |
FWIW, I agree. I'm perfectly happy with methods, as long as the names and their correspondence are clear (e.g. If we want to introduce APIs that mimic the behavior of more complex built-in Python functions, they should probably be free functions as well. |
Ok I will give up on the |
I'll follow up with the simpler changes as a separate PR, for easier reviewing. |
This is a follow up to my comment in #886 . There's two ideas here that I've been thinking about for a while.
I'd be really interested to hear what you think of these ideas, and if you like them, I will finish off this PR according to feedback received.
ObjectProtocol isn't needed any more
get_super()
some time ago, it's very nice ifPyList
etc. implementDeref
forPyAny
. This is now very easy to do with New Native Types and Lighter GILPool #887 merged.Deref
is implemented, I don't thinkObjectProtocol
serves any special purpose not served by just putting the methods directly onPyAny
. So I moved them there.PyAny
to see all the methods they can call. Also removing a trait makes less things for users to understand.PyAny
) rather than for everyT
which implementsObjectProtocol
.More pythonic
repr()
,str()
etc.If I have an object
o
in Python I can get itsrepr
by either doingrepr(o)
oro.__repr__()
. So in my opinion pyo3 should offer the same API.To allow this, I:
pyo3::builtin_methods
which for the moment just hasrepr
,str
,len
andhash
.PyAny::__repr__
PyAny::repr
etc.After this change, I can now call either
pyo3::repr(o)
, oro.__repr__()
.TODO:
PyAny
methodspyo3::builtin_methods
getattr
,setattr
,bool
etc. (https://docs.python.org/3/library/functions.html)