-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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 the 'wrapper_descriptor' type to the types module #73563
Comments
There currently is no type in the types module for the slot wrappers/wrapper_descriptor types. I would like to have something like WrapperDescriptor = type(object.__init__) added to it (or maybe even add it to MethodType). This would be helpful to check more easily if some object is a method. I can create a pull request for this if desired. |
Manuel, it would be helpful if you submit a patch. Guido, this is necessary for |
I would suggest the names SlotWrapperType and MethodWrapperType because I think they match their string representations the closest. For checking whether something is a method/function one could also use inspect.isroutine (or inspect.ismethoddescriptor), but that is inconsistent with regards to builtin and python methods: >>> import inspect
>>> inspect.isroutine(object.__init__)
True
>>> inspect.isroutine(object().__init__)
False
>>> class A:
... def f(self):
... pass
...
>>> inspect.isroutine(A.f)
True
>>> inspect.isroutine(A().f)
True Maybe a function to detect the second case is needed. |
Manuel, thank you for a patch! Two comments:
|
I added some docs, but I am not sure what I would want to test here. There are no tests for types.BuiltinMethodType either. Maybe the string representation of it could be tested, but an isinstance test seems pretty redundant. I hope this patch file works better, I created the last one with git diff. |
Tests are never redundant :-) Just add one-two asserts that you think should be true about issubclass and isinstance with these types (like self.assertIsInstance(''.__add__, types.MethodWrapperType)). String representation on the contrary is less important. For some reason your patch is still not recognized by review tool. But don't worry about this, if it will not work, I will try to fix it. |
Alright, I added some tests and tried it again with the patch. |
I created the last patch without commiting, so maybe this one will work properly with the revision tool. |
Manuel, thank you for the new patch now everything works. I have few more comments:
|
Okay, I added MethodDescriptorType to the types module and updated the docs. Hope this is okay now. |
Thank you! Guido, Yury, could one of you please take a look at this? |
Seems the combined patch doesn't include the tests. Nor does the most recent slot-wrappre-types.patch. Ivan, can you make a single truly combined patch and add a Misc/NEWS entry to it as well? Other than that this looks fine. Maybe we need to wait for the github migration to complete though? |
One question I was wondering about is whether those types should be checked by inspect.isroutine() as well. |
Guido, I attach the full patch now, as you asked. (Initially I was not sure about tests, but now I understand more these types, so that I added even few more tests than in original patch)
I think it is OK to merge this now, but if it would be easier for you then it is not a problem to wait until GH migration is complete. Manuel, I think that probably the answer is yes, but I would prefer a separate issue for the inspect module. You could open a new issue and mention this one as a dependency. |
New changeset 3db1959c2c53 by Guido van Rossum in branch 'default': |
Thanks Manuel and Ivan! |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: