mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +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):
|
def add_codes(err_cls):
|
||||||
"""Add error codes to string messages via class attribute names."""
|
"""Add error codes to string messages via class attribute names."""
|
||||||
|
|
||||||
class ErrorsWithCodes(object):
|
class ErrorsWithCodes(err_cls):
|
||||||
def __getattribute__(self, code):
|
def __getattribute__(self, code):
|
||||||
if not code.startswith('__'):
|
msg = super().__getattribute__(code)
|
||||||
msg = getattr(err_cls, code)
|
if code.startswith('__'): # python system attributes like __class__
|
||||||
return "[{code}] {msg}".format(code=code, msg=msg)
|
return msg
|
||||||
else:
|
else:
|
||||||
return super().__getattribute__(code)
|
return "[{code}] {msg}".format(code=code, msg=msg)
|
||||||
|
|
||||||
return ErrorsWithCodes()
|
return ErrorsWithCodes()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from inspect import isclass
|
from inspect import isclass
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from spacy.errors import add_codes
|
from spacy.errors import add_codes
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,4 +12,6 @@ class Errors(object):
|
||||||
|
|
||||||
def test_add_codes():
|
def test_add_codes():
|
||||||
assert Errors.E001 == "[E001] error description"
|
assert Errors.E001 == "[E001] error description"
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
Errors.E002
|
||||||
assert isclass(Errors.__class__)
|
assert isclass(Errors.__class__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user