mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 00:46:28 +03:00
fixup! Fix ErrorsWithCodes().__class__ return value
This commit is contained in:
parent
a987e9e45d
commit
712d9d4820
|
@ -5,13 +5,13 @@ from __future__ import unicode_literals
|
|||
def add_codes(err_cls):
|
||||
"""Add error codes to string messages via class attribute names."""
|
||||
|
||||
class ErrorsWithCodes(object):
|
||||
class ErrorsWithCodes(err_cls):
|
||||
def __getattribute__(self, code):
|
||||
if not code.startswith('__'):
|
||||
msg = getattr(err_cls, code)
|
||||
return "[{code}] {msg}".format(code=code, msg=msg)
|
||||
msg = super().__getattribute__(code)
|
||||
if code.startswith('__'): # python system attributes like __class__
|
||||
return msg
|
||||
else:
|
||||
return super().__getattribute__(code)
|
||||
return "[{code}] {msg}".format(code=code, msg=msg)
|
||||
|
||||
return ErrorsWithCodes()
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from inspect import isclass
|
||||
|
||||
import pytest
|
||||
|
||||
from spacy.errors import add_codes
|
||||
|
||||
|
||||
|
@ -10,4 +12,6 @@ class Errors(object):
|
|||
|
||||
def test_add_codes():
|
||||
assert Errors.E001 == "[E001] error description"
|
||||
with pytest.raises(AttributeError):
|
||||
Errors.E002
|
||||
assert isclass(Errors.__class__)
|
||||
|
|
Loading…
Reference in New Issue
Block a user