Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day3 orm.py Undefined variable 'StandardError' #54

Open
pretendhigh opened this issue Jan 11, 2020 · 2 comments
Open

Day3 orm.py Undefined variable 'StandardError' #54

pretendhigh opened this issue Jan 11, 2020 · 2 comments

Comments

@pretendhigh
Copy link

python 版本 Python 3.7.3
vscode 中显示 orm.py 报错: Undefined variable 'StandardError'
class ModelMetaclass(type):

def __new__(cls, name, bases, attrs):
    if name=='Model':
        return type.__new__(cls, name, bases, attrs)
    tableName = attrs.get('__table__', None) or name
    logging.info('found model: %s (table: %s)' % (name, tableName))
    mappings = dict()
    fields = []
    primaryKey = None
    for k, v in attrs.items():
        if isinstance(v, Field):
            logging.info('  found mapping: %s ==> %s' % (k, v))
            mappings[k] = v
            if v.primary_key:
                # 找到主键:
                if primaryKey:
                    raise StandardError('Duplicate primary key for field: %s' % k)

stackoverflow 中有个回答, "exception StandardError which was removed in Python 3.",是这样的吗?

@fgetwewr
Copy link

The StandardError class is removed in Python 3. It was the base class for built-in exceptions, and it proved to be an unnecessary link in almost any exception’s inheritance chain.

The recommended fixer will replace all uses of StandardError with Exception. Review the result to check if this is correct.

Some code might rely on the name of an exception class, or on exceptions not derived from StandardError, or otherwise handle StandardError specially. You’ll need to handle these casses manually.

@xieyupengzZ
Copy link

在Python 3里,StandardError已经被取消了,使用Exception替代。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants