Skip to content

Commit

Permalink
TODO for improving ViewMethod init
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Dec 5, 2023
1 parent edde537 commit 0db8de7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/coaster/views/classview.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ def decorator(
return decorator


def viewdata(
**kwargs,
) -> ViewDataDecoratorProtocol:
def viewdata(**kwargs) -> ViewDataDecoratorProtocol:
"""
Decorate view to add additional data alongside :func:`route`.
Expand Down Expand Up @@ -285,7 +283,7 @@ def __init__(
self.data = data or {}
self.endpoints: t.Set[str] = set()

# Are we decorating another ViewHelper? If so, copy routes and func from it.
# Are we decorating another ViewMethod? If so, copy routes and func from it.
if isinstance(decorated, ViewMethod):
self.routes.extend(decorated.routes)
newdata = dict(decorated.data)
Expand Down Expand Up @@ -368,6 +366,7 @@ def init_app(
* :attr:`endpoints`: The URL endpoints registered to this view handler
"""

# TODO: Move most of this into `__set_name__`
def view_func(**view_args) -> BaseResponse:
this = cast(ViewFuncProtocol, view_func)
# view_func does not make any reference to variables from init_app to avoid
Expand All @@ -382,7 +381,7 @@ def view_func(**view_args) -> BaseResponse:
viewinst.current_handler = ViewHandler(
# Mypy is incorrectly applying the descriptor protocol to a non-class's
# dict, and therefore concluding this.view.__get__() -> ViewHandler,
# instead of this.view just remaining a ViewHelper, sans descriptor call
# instead of this.view just remaining a ViewMethod, sans descriptor call
# https://github.com/python/mypy/issues/15822
this.view, # type: ignore[arg-type]
viewinst,
Expand Down

0 comments on commit 0db8de7

Please sign in to comment.