Fix ErrorsWithCodes().__class__ return value

This commit is contained in:
Ilia Ivanov 2020-05-14 14:14:15 +02:00
parent 9ce059dd06
commit a987e9e45d
2 changed files with 18 additions and 2 deletions

View File

@ -7,8 +7,11 @@ def add_codes(err_cls):
class ErrorsWithCodes(object):
def __getattribute__(self, code):
msg = getattr(err_cls, code)
return "[{code}] {msg}".format(code=code, msg=msg)
if not code.startswith('__'):
msg = getattr(err_cls, code)
return "[{code}] {msg}".format(code=code, msg=msg)
else:
return super().__getattribute__(code)
return ErrorsWithCodes()

View File

@ -0,0 +1,13 @@
from inspect import isclass
from spacy.errors import add_codes
@add_codes
class Errors(object):
E001 = "error description"
def test_add_codes():
assert Errors.E001 == "[E001] error description"
assert isclass(Errors.__class__)