Skip to content
Myr

inform mypy that g has arbitrary attributes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 2baaa8f · Browse files · 2 files+22 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−2 removed

  • other:+22 added−2 removed

2 files+22 added−2 removed

modified:src/flask/ctx.py+20 added-2 removed
39 unmodified lines
4041 .. versionadded:: 0.1042 """4344 # Define attr methods to let mypy know this is a namespace object45 # that has arbitrary attributes.4647 def __getattr__(self, name: str) -> t.Any:48 try:49 return self.__dict__[name]50 except KeyError:51 raise AttributeError(name) from None5253 def __setattr__(self, name: str, value: t.Any) -> None:54 self.__dict__[name] = value5556 def __delattr__(self, name: str) -> None:57 try:58 del self.__dict__[name]59 except KeyError:60 raise AttributeError(name) from None6162 def get(self, name: str, default: t.Optional[t.Any] = None) -> t.Any:63 """Get an attribute by name, or a default value. Like64 :meth:`dict.get`.65
29 unmodified lines
95 .. versionadded:: 0.1196 """97 return self.__dict__.setdefault(name, default)9881 def __contains__(self, item: t.Any) -> bool:99 def __contains__(self, item: str) -> bool:100 return item in self.__dict__10184 def __iter__(self) -> t.Iterator:102 def __iter__(self) -> t.Iterator[str]:103 return iter(self.__dict__)104105 def __repr__(self) -> str:106 top = _app_ctx_stack.top
372 unmodified lines
modified:CHANGES.rst+2 added
8 unmodified lines
9 ``filename`` parameter has been renamed to ``path``, the old name10 is deprecated. :pr:`4019`11- Mark top-level names as exported so type checking understands12 imports in user projects. :issue:`4024`13- Fix type annotation for ``g`` and inform mypy that it is a namespace14 object that has arbitrary attributes. :issue:`4020`151617Version 2.0.018-------------
1096 unmodified lines