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?

Multi tool use
Multi tool use

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















                    eeY0BKMb,4o,it1l2NCLZikji,c
                    IuKTCsT89,O5NTCqroSp2 ddo2vY410z0iD nUG3kBBjm6Axqnx5M0m RE1

                    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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe