Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson
On 13Nov2022 10:08, Cameron Simpson wrote: On 13Nov2022 07:57, Cameron Simpson wrote: # replace fctory with a function calling factory.__func__ factory = lambda arg: factory.__func__(classmethod, arg) It just occurred to me that you might need to grab the value of factor

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson
On 13Nov2022 07:57, Cameron Simpson wrote: # replace fctory with a function calling factory.__func__ factory = lambda arg: factory.__func__(classmethod, arg) It just occurred to me that you might need to grab the value of factory.__func__ first: factory0 = factory

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Ian Pilcher
On 11/12/22 14:57, Cameron Simpson wrote: You shouldn't need a throwaway class, just use the name "classmethod" directly - it's the type!     if not callable(factory):     if type(factory) is classmethod:     # replace fctory with a function calling factory.__func__    

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson
On 12Nov2022 10:34, Ian Pilcher wrote: So I've done this. class _HasUnboundClassMethod(object): @classmethod def _classmethod(cls): pass # pragma: no cover _methods = [ _classmethod ] _ClassMethodType = type(_HasUnboundClassMethod._methods[0]) Which allo

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson
On 12Nov2022 18:44, Weatherby,Gerard wrote: Use the inspect module as Cameron suggested. My suggestions was not for the post-construction class attributes but for the comtents of the "_attrs" mapping. Post construction the class method is callable. But the classmethod object stashed in "_att

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Weatherby,Gerard
def double(x): return x + x def triple(self, y): return 3 * y analyze_class(Demo) output: Demo.double-> probably a static method Demo.triple-> probably a bound method Demo.us -> class method From: Python-list on behalf of Ian Pilcher Date: Saturday, November 12, 2022

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Ian Pilcher
On 11/11/22 16:47, Cameron Simpson wrote: On 11Nov2022 15:29, Ian Pilcher wrote: * Can I improve the 'if callable(factory):' test above?  This treats  all non-callable objects as classmethods, which is obviously not  correct.  Ideally, I would check specifically for a classmethod, but  there do

Re: Dealing with non-callable classmethod objects

2022-11-11 Thread Dieter Maurer
Ian Pilcher wrote at 2022-11-11 15:29 -0600: > ... >In searching, I've found a few articles that discuss the fact that >classmethod objects aren't callable, but the situation actually seems to >be more complicated. > > >>> type(DuidLLT._parse_l2addr) > > >>> callable(DuidLLT._parse_l2addr) >True >

Re: Dealing with non-callable classmethod objects

2022-11-11 Thread Cameron Simpson
On 11Nov2022 15:29, Ian Pilcher wrote: I am trying to figure out a way to gracefully deal with uncallable classmethod objects. I'm just going to trim your example below a bit for reference purposes: class DUID(object): def __init__(self, d): for attr, factory in self._attrs.items()

Dealing with non-callable classmethod objects

2022-11-11 Thread Ian Pilcher
I am trying to figure out a way to gracefully deal with uncallable classmethod objects. The class hierarchy below illustrates the issue. (Unfortunately, I haven't been able to come up with a shorter example.) import datetime class DUID(object): _subclasses = {} def __init_subclass__