Skip to content

Instantly share code, notes, and snippets.

@Daetalus
Last active November 5, 2015 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daetalus/09441b1d5c2c13c6ded8 to your computer and use it in GitHub Desktop.
Save Daetalus/09441b1d5c2c13c6ded8 to your computer and use it in GitHub Desktop.
How to get cls information from class method?
# dict.fromkeys(...) could not set the class information for subclass correctly.
# so I want to correct it.
# Original code is here:
# auto* fromkeys_func
# = new BoxedFunction(FunctionMetadata::create((void*)dictFromkeys, DICT, 3, false, false), { None });
# dict_cls->giveAttr("fromkeys", boxInstanceMethod(dict_cls, fromkeys_func, dict_cls));
# I think we should not hardcode the cls information here. And also I want to change it to BoxedBuiltinFunctionOrMethod.
# But I don't know how to get the class information if use `fromkeys` like a class method, for example:
class dictlike(dict):
pass
a = dictlike()
b = a.fromkeys("b")
# in Pyston, get the cls information by
# Box* dictFromKeys(Box* self, ...) {
# BoxedClass* cls = self->cls;
a = dictlike.fromkeys("a")
# how to get the cls information in this situation in Pyston?
# Neither `cls = self->cls;` nor `cls = static_cast<BoxedClass*>self` will work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment