Search code examples
pythonpython-2.7ethereum

Don't understand this SyntaxError about the metaclass


Codes below are atomic.py from the pyrlp package, which is a library of pyethereum.

import abc


class Atomic(metaclass=abc.ABCMeta):
    """ABC for objects that can be RLP encoded as is."""
    pass


Atomic.register(bytes)
Atomic.register(bytearray)

And here is the error information from the console:

from rlp.atomic import Atomic
  File "/Users/jerryin/Desktop/pyeth/pyrlp/rlp/atomic.py", line 4
    class Atomic(metaclass=abc.ABCMeta):
                          ^
SyntaxError: invalid syntax

I've not modified the project since it was imported. Could anyone please tell me what's wrong with this?

Plus, the interpreter I used for this project is Python 2.7.


Solution

  • Python 2 does not support the metaclass keyword argument to classes, and pyrlp dropped support for Python 2 in April 2018.

    Use Python 3 instead.