Skip to content

Commit

Permalink
Additional typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Apr 17, 2024
1 parent a6fa7ab commit 1ca45d3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/coaster/sqlalchemy/markdown.py
Expand Up @@ -81,7 +81,7 @@ def text(self, value: Optional[str]) -> None:
)
self.changed()

def __json__(self) -> dict[str, Optional[str]]:
def __json__(self) -> Any:
"""Return JSON-compatible rendering of composite."""
return {'text': self._text, 'html': self._html}

Expand Down
2 changes: 1 addition & 1 deletion src/coaster/sqlalchemy/roles.py
Expand Up @@ -1049,7 +1049,7 @@ def __setitem__(self, key: str, value: str) -> None:
def __iter__(self) -> Iterator[str]:
yield from self._all_read

def __json__(self) -> dict[str, Any]:
def __json__(self) -> Any:
if self._datasets is None and self._obj.__json_datasets__:
# This proxy was created without specifying datasets, so we create a new
# proxy using the object's default JSON datasets, then convert it to a dict
Expand Down
4 changes: 2 additions & 2 deletions src/coaster/views/decorators.py
Expand Up @@ -9,7 +9,7 @@

from __future__ import annotations

from collections.abc import Collection, Container, Iterable
from collections.abc import Collection, Container, Iterable, Mapping
from functools import wraps
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, TypeVar, Union, cast
from typing_extensions import ParamSpec
Expand Down Expand Up @@ -50,7 +50,7 @@
'requires_permission',
]

ReturnRenderWithData = dict[str, Any]
ReturnRenderWithData = Mapping[str, Any]
ReturnRenderWithResponse = Union[WerkzeugResponse, ReturnRenderWithData]
ReturnRenderWithHeaders = Union[list[tuple[str, str]], dict[str, str], Headers]
ReturnRenderWith = Union[
Expand Down
4 changes: 2 additions & 2 deletions tests/coaster_tests/views_classview_test.py
Expand Up @@ -349,12 +349,12 @@ def before_request(

@route('perm')
@requires_permission('edit')
def by_perm(self):
def by_perm(self) -> str:
return 'perm-called'

@route('role')
@requires_roles({'owner'})
def by_role(self):
def by_role(self) -> str:
return 'role-called'

@route('perm-role')
Expand Down
3 changes: 2 additions & 1 deletion tests/coaster_tests/views_renderwith_test.py
@@ -1,4 +1,5 @@
import unittest
from collections.abc import Mapping
from typing import Any

import pytest
Expand All @@ -13,7 +14,7 @@
app = Flask(__name__)


def viewcallable(data: dict[str, Any]) -> BaseResponse:
def viewcallable(data: Mapping[str, Any]) -> BaseResponse:
return Response(repr(data), mimetype='text/plain')


Expand Down

0 comments on commit 1ca45d3

Please sign in to comment.