Skip to content

Commit

Permalink
style(utility): do not check the type of "__getattr__" in "AttrsMixin"
Browse files Browse the repository at this point in the history
Mypy does not raise an error on a `missing method` when base class
defines a `__getattr__` function, so make mypy ignore that method
by decorating `__getattr__` with `typing.no_type_check`.

related issue: python/mypy#6251
  • Loading branch information
zhen.chen committed May 26, 2021
1 parent e056c1d commit 2974ac0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tensorbay/utility/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
"""

from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union
from typing import (
Any,
Callable,
Dict,
List,
NoReturn,
Optional,
Tuple,
TypeVar,
Union,
no_type_check,
)

from typing_extensions import Protocol

Expand Down Expand Up @@ -65,7 +76,7 @@ def __init__(
if error_message:
self.error_message = error_message

def __getattr__(self, name: str) -> None:
def __getattr__(self, name: str) -> NoReturn:
raise AttributeError(
_DEFAULT_ERROR_MESSAGE.format(class_name=self.__class__.__name__, attr_name=name)
)
Expand Down Expand Up @@ -123,7 +134,8 @@ def __eq__(self, other: object) -> bool:

return self.__dict__ == other.__dict__

def __getattr__(self, name: str) -> None:
@no_type_check
def __getattr__(self, name: str) -> NoReturn:
"""Raise an AttributeError exception when an attr does not exist.
Arguments:
Expand Down

0 comments on commit 2974ac0

Please sign in to comment.