我试图为django1.8更新^{SQLDateCompiler
在1.8版中完全从django中删除了。django_pyodbc
正在扩展SQLDateCompiler
(我们称之为SQLDateCompilerPrime
),它现在已经不存在了。你知道吗
当用户在实例化类之前从SQLDateCompiler
继承时,我想发出一个弃用错误/异常。你知道吗
我知道如何使用python的^{
我可以做:
class SQLDateCompilerPrime(object):
def __init__(self, *args, **kwargs):
warnings.warn(
'In the 1.8 release of django, `SQLDateCompiler` was removed. ' +
'This was the basis of `SQLDateCompilerPrime`, and thus ' +
'`SQLDateCompilerPrime` is no longer available.',
DeprecationWarning, stacklevel=2)
但是,这只会在创建子类的实例时失败。我想在子类定义为时失败,并立即发出警告。完全删除该定义肯定会导致失败,但我不希望用户必须查看其他django_pyodbc
才能发现它不再是定义的,只是从它们下面消失了。你知道吗
您可以为此使用元类:
此示例产生以下输出:
相关问题 更多 >
编程相关推荐