PythonCharmers/python-future

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

Open

#267 ouverte le 26 janv. 2017

Voir sur GitHub
 (0 commentaires) (2 réactions) (0 assignés)Python (327 forks)batch import
0.20bughelp wanted

Métriques du dépôt

Stars
 (1 172 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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

Guide contributeur