Skip to content

Commit

Permalink
chore(typing): add more descriptive typing to Context
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 committed Apr 5, 2024
1 parent 7ec1d31 commit 832cabc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions falcon/util/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from typing import KeysView
from typing import Optional
from typing import Tuple
from typing import TYPE_CHECKING
from typing import ValuesView


Expand Down Expand Up @@ -141,6 +142,25 @@ class Context:
True
"""

# NOTE(vytas): Define synthetic attr access methods (under TYPE_CHECKING)
# merely to let mypy know this is a namespace object.
if TYPE_CHECKING:

def __getattr__(self, name: str) -> Any:
try:
return self.__dict__[name]
except KeyError:
raise AttributeError(name) from None

def __setattr__(self, name: str, value: Any) -> None:
self.__dict__[name] = value

def __delattr__(self, name: str) -> None:
try:
del self.__dict__[name]
except KeyError:
raise AttributeError(name) from None

def __contains__(self, key: str) -> bool:
return self.__dict__.__contains__(key)

Expand Down

0 comments on commit 832cabc

Please sign in to comment.