Skip to content

Commit

Permalink
refactor(utility): modify "AttrsMixin" as a workaround for pylint errors
Browse files Browse the repository at this point in the history
`attr()` returns `Field` as the class variables value, using type hint
as the real type of variables.
pylint use `Field` as the variable type, so it will report the following
errors

`E0237: Assigning to attribute 'box2d' not defined in class slots
(assigning-non-slot)`
`E1101: Instance of 'Field' has no 'box3d' member (no-member)`

do the following as a workaround for pylint errors
* remove `__slot__` for E0237
* add `__getattr__` function for E1101

related issue:
pylint-dev/pylint#4341

PR Closed: Graviti-AI#580
  • Loading branch information
zhen.chen committed May 19, 2021
1 parent 21c3b31 commit 1b08a2f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tensorbay/utility/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Field: # pylint: disable=too-few-public-methods
"""

__slots__ = ("is_dynamic", "key", "default", "error_message", "loader", "dumper")
# remove __slots__ and add __getattr__ due to: https://github.com/PyCQA/pylint/issues/4341
# __slots__ = ("is_dynamic", "key", "default", "error_message", "loader", "dumper")

def __init__(
self, is_dynamic: bool, key: str, default: Any, error_message: Optional[str]
Expand All @@ -48,6 +49,11 @@ def __init__(
if error_message:
self.error_message = error_message

def __getattr__(self, name: str) -> None:
raise AttributeError(
_DEFAULT_ERROR_MESSAGE.format(class_name=self.__class__.__name__, attr_name=name)
)


class AttrsMixin:
"""AttrsMixin provides a list of special methods based on attr fields.
Expand Down

0 comments on commit 1b08a2f

Please sign in to comment.