PythonCharmers/python-future

newsuper not working with metaclasses - `RuntimeError: super() called outside a method`

Open

#267 opened on Jan 26, 2017

View on GitHub
 (0 comments) (2 reactions) (0 assignees)Python (1,172 stars) (327 forks)batch import
0.20bughelp wanted

Description

In [1]: from builtins import super
   ...:
   ...: class Meta(type):
   ...:     def __init__(cls, name, bases, clsdict):
   ...:         super().__init__(name, bases, clsdict)
   ...:
   ...: class Base(object):
   ...:     __metaclass__ = Meta
   ...:
   ...:     pass
   ...:
   ...:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-9186c0cb3819> in <module>()
      5         super().__init__(name, bases, clsdict)
      6
----> 7 class Base(object):
      8     __metaclass__ = Meta
      9

<ipython-input-2-300b574b1003> in __init__(cls, name, bases, clsdict)
      3 class Meta(type):
      4     def __init__(cls, name, bases, clsdict):
----> 5         super().__init__(name, bases, clsdict)
      6
      7 class Base(object):

/Users/$USER/miniconda2/lib/python2.7/site-packages/future/builtins/newsuper.pyc in newsuper(typ, type_or_obj, framedepth)
     98             break    #  Found! Break out of the search loop.
     99         else:
--> 100             raise RuntimeError('super() called outside a method')
    101
    102     #  Dispatch to builtin super().

RuntimeError: super() called outside a method

Contributor guide