PythonCharmers/python-future

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

Open

#267 aperta il 26 gen 2017

Vedi su GitHub
 (0 commenti) (2 reazioni) (0 assegnatari)Python (327 fork)batch import
0.20bughelp wanted

Metriche repository

Star
 (1172 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor