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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript