-
Notifications
You must be signed in to change notification settings - Fork 652
Allow for builtin slots to be overriden #71
Comments
Thanks for the report! This is something that I've fretted a bit about. The real trick is that you have to update the slot on all the subclasses. Here's how CPython does it. Unfortunately, whereas CPython holds the GIL while it does all this work, Grumpy must find some other way to synchronize it, or live with poor consistency guarantees around updating types. Worse is when you assign to a type's Personally I think it's crazy to support this kind of monkey patching and I'm inclined to raise an exception when people try things like this. But maybe there are legitimate use cases that I'm overlooking. Thoughts and opinions are welcome here. |
I'm all for raising until a reasonable use case presents itself. At least as long as grumpy is in alpha/beta. |
I would love to monkeypatch datetime.datetime.now() to be allowed to test time in my billing code... |
You're right that tests are a potentially valid use case for that. Note that normal functions (ones that reside in |
A different take on google#71
Travis CI: Simplify using ${SUDO} and ${USER_FLAG}
Consider the following program:
And the following execution of CPython and Grumpy:
CPython allows for the slot method to be overriden at runtime. For the builtins where this applies (which can be determined from
Objects/typeobject.c
in the CPython source), Grumpy should lookup the method by name.That being said, I don't know how common this is in real code. I noticed it reading the CPython source while implementing
__cmp__
.The text was updated successfully, but these errors were encountered: