« first day (2647 days earlier)      last day (2308 days later) » 
00:00 - 23:0023:00 - 00:00

11:09 PM
Which part of that was a complaint?
Is there an equivalent of the vars function that also lists inherited attributes?
 
As in attributes coming from a base class?
 
Something like this:
class A:
    a = 3

class B(A):
    pass

assert 'a' in vars(B)
I guess that works if I combine it with getattr
 
There's inspect.getmembers
 
Okay, next level. How about this:
class M(type):
    m = 6

class A(metaclass=M):
    pass

assert 'm' in dir(A)
inspect.getmembers doesn't pick that up either
 
@JacobWood for the record, I don't disagree with you that coldspeed complains a lot, but a lot of users agree that we shouldn't be answering fundamentally basic/typo questions on main. The former are almost always dupes, and the latter---while on-topic---are usually not helpful for future readers, and they should be closed as such. So whatever you might think of coldspeed, please consider refraining from answering such questions for the long-term benefit of the site.
I know, but I also know that you've been nudged multiple times about answering typo questions and the like :)
 
11:25 PM
@JacobWood Woah, magic. I'll have to read up on that one.
 
oh nevermind, I tried that with an instance rather than a class *facepalm*
 
Ah, but that fails in the case of a nonexistent metaclass:
class A:
    m = 6

assert 'm' in A.__dir__(A)
# AssertionError
 
Dunders? Egad
 
wonder if there's a dunderless way to call that, dir() doesn't seem to be able to do so
 
nvm, that was incorrect
 
11:32 PM
how about recursively crawling A.mro()?
is that stupid?
 
I think dir does that for me? I'm just struggling to get it right when metaclasses are involved
 
If you can define a custom __dir__ for your metaclass, the inspect.getmembers approach will work
Something as simple as
def __dir__(self):
    return dir(type(self))
 
I'm trying to make this work with arbitrary objects, unfortunately. Don't have control over the metaclass.
 
Then you're stuck between a rock and a hard place
 
I think what's tripping me up is that dir has different behavior for classes and instances. Calling dir on an instance lists attributes defined in the class, but calling dir on a class doesn't list attributes defined in the metaclass.
 
11:38 PM
I dislike when people ask me this, but why do you need this?
 
boooo vaultah ;)
 
:P
 
Uh, let's see, into how much detail do I have to go with this explanation...
 
You don't owe me an explanation
 
Good guy vaultah
 
11:43 PM
Is it enough if I say I want to have a decorator that can be used to "mark" a function, and then later I have to find that function? Think something like this:
class MyClass:
    @special_method
    def f(self):
        ...

method = find_special_method(MyClass())
And I want it to work with metaclasses because I'm a perfectionist. Every now and then, at least.
 
@cᴏʟᴅsᴘᴇᴇᴅ Good point. May as well make other people hack together a solution for me :D
@vaultah Sorry, I don't follow. The special_method decorator never even sees self, does it?
 
Can you change the definition of special_method?
 
I can, yes. Both special_method and find_special_method will be written by me.
 
(this reminds me of our recent discussion about whether decorators can see default args)
 
11:55 PM
That's slightly different though. You can use introspection to look at the function's parameters and default values, but the actual arguments (i.e. the non-default values) are out of your reach. There's no guarantee the function is ever called, after all, so there might never be any arguments.
 
@Rawing yup, I had a vague feeling along those lines
hence the parentheses :D
 
00:00 - 23:0023:00 - 00:00

« first day (2647 days earlier)      last day (2308 days later) »