提交 5a1a147d authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Make MetaType extend ABCMeta

This causes `abstractmethod`-decorated methods to take effect (i.e. classes that don't implement these required methods will fail during construction).
上级 f98754f1
...@@ -30,6 +30,9 @@ class MyType(Type): ...@@ -30,6 +30,9 @@ class MyType(Type):
def __init__(self, thingy): def __init__(self, thingy):
self.thingy = thingy self.thingy = thingy
def filter(self, *args, **kwargs):
raise NotImplementedError()
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, MyType) and other.thingy == self.thingy return isinstance(other, MyType) and other.thingy == self.thingy
......
...@@ -12,6 +12,9 @@ class TestNodeFinder: ...@@ -12,6 +12,9 @@ class TestNodeFinder:
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
def filter(self, *args, **kwargs):
raise NotImplementedError()
def __str__(self): def __str__(self):
return self.name return self.name
......
import linecache import linecache
import sys import sys
import traceback import traceback
from abc import ABCMeta
from io import StringIO from io import StringIO
...@@ -157,7 +158,7 @@ class MethodNotDefined(Exception): ...@@ -157,7 +158,7 @@ class MethodNotDefined(Exception):
""" """
class MetaType(type): class MetaType(ABCMeta):
def __new__(cls, name, bases, dct): def __new__(cls, name, bases, dct):
props = dct.get("__props__", None) props = dct.get("__props__", None)
if props is not None: if props is not None:
...@@ -220,7 +221,7 @@ class MetaType(type): ...@@ -220,7 +221,7 @@ class MetaType(type):
dct["__str__"] = __str__ dct["__str__"] = __str__
return type.__new__(cls, name, bases, dct) return super().__new__(cls, name, bases, dct)
class MetaObject(metaclass=MetaType): class MetaObject(metaclass=MetaType):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论