mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Fix ErrorsWithCodes().__class__ return value
This commit is contained in:
parent
9ce059dd06
commit
a987e9e45d
|
@ -7,8 +7,11 @@ def add_codes(err_cls):
|
||||||
|
|
||||||
class ErrorsWithCodes(object):
|
class ErrorsWithCodes(object):
|
||||||
def __getattribute__(self, code):
|
def __getattribute__(self, code):
|
||||||
msg = getattr(err_cls, code)
|
if not code.startswith('__'):
|
||||||
return "[{code}] {msg}".format(code=code, msg=msg)
|
msg = getattr(err_cls, code)
|
||||||
|
return "[{code}] {msg}".format(code=code, msg=msg)
|
||||||
|
else:
|
||||||
|
return super().__getattribute__(code)
|
||||||
|
|
||||||
return ErrorsWithCodes()
|
return ErrorsWithCodes()
|
||||||
|
|
||||||
|
|
13
spacy/tests/test_errors.py
Normal file
13
spacy/tests/test_errors.py
Normal 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__)
|
Loading…
Reference in New Issue
Block a user