-
Notifications
You must be signed in to change notification settings - Fork 768
[WIP] Implement __instancecheck__. #167
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
[WIP] Implement __instancecheck__. #167
Conversation
|
Apparently the |
|
I'm not 100% sure, but it seems like it could be because Exceptions are a special case because they weren't new style classes until Python 2.5 (I think?) and so having them inherit from a new style class (like System.Object) would cause problems. This definitely isn't an issue in Python 3 (and the code for wrapping Exceptions is a lot simpler), but I guess it still could be an issue for Python 2.4 and below. It might be worth trying Python 2.4 or 2.3 to see if this change breaks anything there (even though I know we don't have CI builds or distribute wheels for older versions of Python, but if we can maintain backwards compatibility without too much trouble then it would be nice to). |
|
Is there a specific reason that the Marshal structs aren't used directly but only to get the correct offsets? |
|
@filmor I don't know I'm afraid. This code is pretty old, so possibly that was the only way to do it at the time it was originally written. |
|
@filmor wrt writing the whole null struct, I was just thinking about how it would look if you were to write it in C, i.e. I don't think it explicitly says which member is checked for null-ness in the python docs. The way you had it is probably fine, I was just thinking about how most extensions look and what potential problems could be caused by having it slightly different. |
|
I think you are right there and I've already changed that. I don't know why, but for some reason I though it looked like Now, if we can decide on what to do with the exception test I'd implement |
|
@filmor for the unit test, an option would be to check that Exception is an instance of Object for Python >= 2.6 (since that's when instancecheck was added) and leave it as it is for previous versions of Python. That would check the isinstance change is working correctly, and if anyone ever did want to use an earlier versions of Python then the previous test would still be correct (and this change won't break anything in Python 2.3 since it's not actually changing the base class of anything). |
|
Now, this is only missing a few tests for this specific behaviour, but apart from that it would be good if you could review the changes. |
|
@filmor looks good to me, thanks! |
[WIP] Implement __instancecheck__.
This implements the
__instancecheck__method on the CLR metaclass which results inisinstanceworking for interfaces. I'm not completely sure whether everything still works and this is missing the__subclasscheck__to makeissubclasswork accordingly.Also, I'd like to simplify the method def generation in
MethodWrapperand this particular implementation as a prerequisite to implementing__enter__and__exit__forIDisposableobjects.