Are staticmethod and classmethod in python not callable? [duplicate]Why are python static/class method not callable?Calling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?Meaning of @classmethod and @staticmethod for beginner?

Bash Array of Word-Splitting Headaches

How does the "reverse syntax" in Middle English work?

Is my company merging branches wrong?

Greek theta instead of lower case þ (Icelandic) in TexStudio

Is it wise to pay off mortgage with 401k?

Can anyone provide me info what this is?

Can the word crowd refer to just 10 people?

Failing students when it might cause them economic ruin

Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?

pwaS eht tirsf dna tasl setterl fo hace dorw

Have the writers and actors of Game Of Thrones responded to its poor reception?

Isn't Kirchhoff's junction law a violation of conservation of charge?

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

Warped chessboard

Better than Rembrandt

What city and town structures are important in a low fantasy medieval world?

Is the free group on two generators generated by two elements?

Should I twist DC power and ground wires from a power supply?

Very serious stuff - Salesforce bug enabled "Modify All"

In Dutch history two people are referred to as "William III"; are there any more cases where this happens?

Can a problematic AL DM/organizer prevent me from running a separate AL-legal game at the same store?

Why didn't Daenerys' advisers suggest assassinating Cersei?

Why should one apply for UK visa before other visas, on a multi-destination European holiday?

Why could the Lunar Ascent Engine be used only once?



Are staticmethod and classmethod in python not callable? [duplicate]


Why are python static/class method not callable?Calling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?Meaning of @classmethod and @staticmethod for beginner?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2
















This question already has an answer here:



  • Why are python static/class method not callable?

    1 answer



I was writing a metaclass to force docstring for class and instance method. Well to my surprise staticmethod and classmethod are not callable just like instance method. I am not sure why?



class MyMeta(type):
def __new__(cls, name, parents, attrs):
print(cls, name, parents, attrs)

if "__doc__" not in attrs:
raise TypeError("Please define class level doc string!!!")

for key, value in attrs.items():
if callable(value) and value.__doc__ is None:
raise TypeError("Please define def level doc string!!!")

return super().__new__(cls, name, parents, attrs)

class A(metaclass=MyMeta):
"""This is API doc string"""
def hello(self):
""""""
pass

def __init__(self):
"""__init__ Method"""
pass

@classmethod
def abc(cls):
pass


I am not able to understand why are they not callable? They seems to pass my check if I don't define docstring for them.










share|improve this question















marked as duplicate by Aran-Fey, Community Mar 23 at 18:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























    2
















    This question already has an answer here:



    • Why are python static/class method not callable?

      1 answer



    I was writing a metaclass to force docstring for class and instance method. Well to my surprise staticmethod and classmethod are not callable just like instance method. I am not sure why?



    class MyMeta(type):
    def __new__(cls, name, parents, attrs):
    print(cls, name, parents, attrs)

    if "__doc__" not in attrs:
    raise TypeError("Please define class level doc string!!!")

    for key, value in attrs.items():
    if callable(value) and value.__doc__ is None:
    raise TypeError("Please define def level doc string!!!")

    return super().__new__(cls, name, parents, attrs)

    class A(metaclass=MyMeta):
    """This is API doc string"""
    def hello(self):
    """"""
    pass

    def __init__(self):
    """__init__ Method"""
    pass

    @classmethod
    def abc(cls):
    pass


    I am not able to understand why are they not callable? They seems to pass my check if I don't define docstring for them.










    share|improve this question















    marked as duplicate by Aran-Fey, Community Mar 23 at 18:48


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      2












      2








      2









      This question already has an answer here:



      • Why are python static/class method not callable?

        1 answer



      I was writing a metaclass to force docstring for class and instance method. Well to my surprise staticmethod and classmethod are not callable just like instance method. I am not sure why?



      class MyMeta(type):
      def __new__(cls, name, parents, attrs):
      print(cls, name, parents, attrs)

      if "__doc__" not in attrs:
      raise TypeError("Please define class level doc string!!!")

      for key, value in attrs.items():
      if callable(value) and value.__doc__ is None:
      raise TypeError("Please define def level doc string!!!")

      return super().__new__(cls, name, parents, attrs)

      class A(metaclass=MyMeta):
      """This is API doc string"""
      def hello(self):
      """"""
      pass

      def __init__(self):
      """__init__ Method"""
      pass

      @classmethod
      def abc(cls):
      pass


      I am not able to understand why are they not callable? They seems to pass my check if I don't define docstring for them.










      share|improve this question

















      This question already has an answer here:



      • Why are python static/class method not callable?

        1 answer



      I was writing a metaclass to force docstring for class and instance method. Well to my surprise staticmethod and classmethod are not callable just like instance method. I am not sure why?



      class MyMeta(type):
      def __new__(cls, name, parents, attrs):
      print(cls, name, parents, attrs)

      if "__doc__" not in attrs:
      raise TypeError("Please define class level doc string!!!")

      for key, value in attrs.items():
      if callable(value) and value.__doc__ is None:
      raise TypeError("Please define def level doc string!!!")

      return super().__new__(cls, name, parents, attrs)

      class A(metaclass=MyMeta):
      """This is API doc string"""
      def hello(self):
      """"""
      pass

      def __init__(self):
      """__init__ Method"""
      pass

      @classmethod
      def abc(cls):
      pass


      I am not able to understand why are they not callable? They seems to pass my check if I don't define docstring for them.





      This question already has an answer here:



      • Why are python static/class method not callable?

        1 answer







      python python-3.x metaclass






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 18:36









      Aran-Fey

      20.8k54180




      20.8k54180










      asked Mar 23 at 18:33









      PravinPravin

      1621319




      1621319




      marked as duplicate by Aran-Fey, Community Mar 23 at 18:48


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Aran-Fey, Community Mar 23 at 18:48


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          2














          They are not callable. classmethod and staticmethod are descriptor objects, and they do not implement __call__. The HOWTO actually gives examples of how you might implement them in pure python, so for example classmethod objects:



          class ClassMethod(object):
          "Emulate PyClassMethod_Type() in Objects/funcobject.c"

          def __init__(self, f):
          self.f = f

          def __get__(self, obj, klass=None):
          if klass is None:
          klass = type(obj)
          def newfunc(*args):
          return self.f(klass, *args)
          return newfunc


          Note, function objects are descriptors too. They just happen to be callable descriptors.






          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            They are not callable. classmethod and staticmethod are descriptor objects, and they do not implement __call__. The HOWTO actually gives examples of how you might implement them in pure python, so for example classmethod objects:



            class ClassMethod(object):
            "Emulate PyClassMethod_Type() in Objects/funcobject.c"

            def __init__(self, f):
            self.f = f

            def __get__(self, obj, klass=None):
            if klass is None:
            klass = type(obj)
            def newfunc(*args):
            return self.f(klass, *args)
            return newfunc


            Note, function objects are descriptors too. They just happen to be callable descriptors.






            share|improve this answer



























              2














              They are not callable. classmethod and staticmethod are descriptor objects, and they do not implement __call__. The HOWTO actually gives examples of how you might implement them in pure python, so for example classmethod objects:



              class ClassMethod(object):
              "Emulate PyClassMethod_Type() in Objects/funcobject.c"

              def __init__(self, f):
              self.f = f

              def __get__(self, obj, klass=None):
              if klass is None:
              klass = type(obj)
              def newfunc(*args):
              return self.f(klass, *args)
              return newfunc


              Note, function objects are descriptors too. They just happen to be callable descriptors.






              share|improve this answer

























                2












                2








                2







                They are not callable. classmethod and staticmethod are descriptor objects, and they do not implement __call__. The HOWTO actually gives examples of how you might implement them in pure python, so for example classmethod objects:



                class ClassMethod(object):
                "Emulate PyClassMethod_Type() in Objects/funcobject.c"

                def __init__(self, f):
                self.f = f

                def __get__(self, obj, klass=None):
                if klass is None:
                klass = type(obj)
                def newfunc(*args):
                return self.f(klass, *args)
                return newfunc


                Note, function objects are descriptors too. They just happen to be callable descriptors.






                share|improve this answer













                They are not callable. classmethod and staticmethod are descriptor objects, and they do not implement __call__. The HOWTO actually gives examples of how you might implement them in pure python, so for example classmethod objects:



                class ClassMethod(object):
                "Emulate PyClassMethod_Type() in Objects/funcobject.c"

                def __init__(self, f):
                self.f = f

                def __get__(self, obj, klass=None):
                if klass is None:
                klass = type(obj)
                def newfunc(*args):
                return self.f(klass, *args)
                return newfunc


                Note, function objects are descriptors too. They just happen to be callable descriptors.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 23 at 18:37









                juanpa.arrivillagajuanpa.arrivillaga

                40k34078




                40k34078















                    Popular posts from this blog

                    Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

                    밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

                    1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴