Repository navigation
py/runtime: Do generic lookup if type->attr fails. - #6253
laurensvalk wants to merge 2 commits into
Conversation
|
Thanks for this alternative, it's definitely much simpler. One thing to check is if there are existing types (eg user defined classes and instances thereof) which do a full lookup in For your use-case would you prefer #4969 or this here? Ultimately both of the patches could be useful for different things, they can both coexist. |
|
Thanks. What about the following? This way, the
Probably still #4969 (or something like it) for most of our use cases, which is returning attributes without running code on them. This new PR originated from a different use case where we did want to run some code on reading a property (return transpose on |
That does sound like a good idea. |
This turns out to be not entirely trivial.
So again quite a few options (and variations of each) and I'm not sure which is the best. In the update that just pushed, I've opted to use |
Make it possible to proceed to a regular lookup in locals_dict if the custom type->attr fails. This allows type->attr to extend rather than completely replace the lookup. This is useful for custom builtin classes that have mostly regular methods but just a few special attributes/properties. This way, type->attr needs to deal with the special cases only and the default lookup will be used for generic methods. Signed-off-by: Laurens Valk <[email protected]>
Clearing it is consistent with other lookups. It is required because type->attr may set dest[1] to MP_OBJ_SENTINEL on failure. Signed-off-by: Laurens Valk <[email protected]>
|
Implemented in e2ca8ab |
…n-main Translations update from Hosted Weblate
If the custom
type->attrfails, don't give up just yet but look in thelocals_dict. This allowstype->attrto extend rather than completelyreplace the lookup.
This is useful for custom builtin classes that have mostly regular
methods but just a few special attributes/properties. This way,
type->attrneeds to deal with the special cases only and the defaultlookup will be used for generic methods.
This is an alternative to #4969.
The original was perhaps slightly more convenient since no custom
attrhandler was required, but this is a much smaller change overall.This new PR is also a bit more generic, as this makes it quite easy to add
properties that do a bit more than just returning an existing attribute.
EDIT: Rebased onto latest master.