Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75338

Re: TypeError: 'NoneType' object is not callable

From Peter Otten <__peter__@web.de>
Subject Re: TypeError: 'NoneType' object is not callable
Date 2014-07-29 09:21 +0200
Organization None
References <a733ac63-f850-4f69-ac80-4095dd6e70a2@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.12404.1406618499.18130.python-list@python.org> (permalink)

Show all headers | View raw


Satish ML wrote:

> Hi,
> 
> TypeError: 'NoneType' object is not callable? Why this error and what is
> the solution? Code:
> class SuperMeta:
>     def __call__(self, classname, supers, classdict):
>         print('In SuperMeta.call: ', classname, supers, classdict,
>         sep='\n...') Class = self.__New__(classname, supers, classdict)
>         self.__Init__(Class, classname, supers, classdict)
> class SubMeta(SuperMeta):
>     def __New__(self, classname, supers, classdict):
>         print('In SubMeta.new: ', classname, supers, classdict,
>         sep='\n...') return type(classname, supers, classdict)
>     def __Init__(self, Class, classname, supers, classdict):
>         print('In SubMeta init:', classname, supers, classdict,
>         sep='\n...') print('...init class object:',
>         list(Class.__dict__.keys()))
> class Eggs:
>     pass
> print('making class')
> class Spam(Eggs, metaclass=SubMeta()):
>     data = 1
>     def meth(self, arg):
>         pass
> print('making instance')
> X = Spam()
> 
> print('data:', X.data)
> Output:
> making class
> In SuperMeta.call:
> ...Spam
> ...(<class '__main__.Eggs'>,)
> ...{'meth': <function Spam.meth at 0x0000000003539EA0>, '__module__':
> '__main__', '__qualname__': 'Spam', 'data': 1} In SubMeta.new:
> ...Spam
> ...(<class '__main__.Eggs'>,)
> ...{'meth': <function Spam.meth at 0x0000000003539EA0>, '__module__':
> '__main__', '__qualname__': 'Spam', 'data': 1} In SubMeta init:
> ...Spam
> ...(<class '__main__.Eggs'>,)
> ...{'meth': <function Spam.meth at 0x0000000003539EA0>, '__module__':
> '__main__', '__qualname__': 'Spam', 'data': 1} ...init class object:
> ['meth', '__module__', 'data', '__doc__'] making instance
> Traceback (most recent call last):
>   File "C:/Users/Satish/Desktop/Python/Metaclasses7.py", line 21, in
>   <module>
>     X = Spam()
> TypeError: 'NoneType' object is not callable

As I have no idea what you are up to I can only list some adjustments you 
probably need to make:

- __init__() and __new__() are spelt in lowercase.
- do not instantiate the metaclass:
  class Spam(Eggs, metaclass=SubMeta): 
      ...
- The metaclasses of Spam and Eggs must share a common base. 
  This can be achieved with
  class SuperMeta(type): 
      ...

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

TypeError: 'NoneType' object is not callable Satish ML <satishmlwizpro@gmail.com> - 2014-07-28 23:49 -0700
  Re: TypeError: 'NoneType' object is not callable Peter Otten <__peter__@web.de> - 2014-07-29 09:21 +0200

csiph-web