Skip to content

Commit

Permalink
Linter and type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Aug 20, 2024
1 parent 2f7f584 commit 3d3df8f
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/coaster/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _require_recursive(self, *namespecs: str) -> list[tuple[str, Version, str]]:
if provided not in asset_versions:
asset_versions[provided] = version
for req_name, req_version, _req_bundle in req_bundles:
asset_versions[req_name] = req_version
asset_versions[req_name] = req_version # noqa: PERF403
if bundle is not None:
bundles.append((name, version, bundle))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/coaster/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def __call__(self) -> CurrentAuth:
@classmethod
def proxy(cls, subcls: type[_CurrentAuthType_co]) -> _CurrentAuthType_co:
"""Create a local proxy using a specific subclass of :class:`CurrentAuth`."""
return cast(_CurrentAuthType_co, LocalProxy(cls(subcls)))
return cast(_CurrentAuthType_co, LocalProxy(cls(subcls))) # type: ignore[arg-type]


#: A proxy object that hosts state for user authentication, attempting to load
Expand Down
9 changes: 1 addition & 8 deletions src/coaster/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,6 @@ async def get_data(
self, cache: bool, as_text: Literal[True], parse_form_data: bool
) -> str: ...

@overload
async def get_data(
self, cache: bool = True, as_text: bool = False, parse_form_data: bool = False
) -> AnyStr: ...

async def get_data(
self, cache: bool = True, as_text: bool = False, parse_form_data: bool = False
) -> AnyStr:
Expand Down Expand Up @@ -593,8 +588,6 @@ def check_return(*args: _P.args, **kwargs: _P.kwargs) -> _R_co:
result = func(*args, **kwargs)
if isawaitable(result):
return sync_await(result)
# The typeguard for `isawaitable` doesn't narrow in the negative context, so we
# need a type-ignore here:
return result # type: ignore[return-value]
return result

return check_return
4 changes: 1 addition & 3 deletions src/coaster/sqlalchemy/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None:
and issubclass(origin_base, IdMixin)
and PkeyType in origin_base.__parameters__ # type: ignore[misc]
):
pkey_type = get_args(base)[
origin_base.__parameters__.index(PkeyType) # type: ignore[misc]
]
pkey_type = get_args(base)[origin_base.__parameters__.index(PkeyType)]
if pkey_type is int:
if (
'__uuid_primary_key__' in cls.__dict__
Expand Down
4 changes: 1 addition & 3 deletions src/coaster/sqlalchemy/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ def __subclasshook__(cls, subcls: type[Any]) -> bool:
"""Check if a class implements the RoleGrantABC protocol."""
if cls is RoleGrantABC:
# Don't use getattr because that'll trigger descriptor __get__ protocol
if any('offered_roles' in b.__dict__ for b in subcls.__mro__):
return True
return False
return bool(any('offered_roles' in b.__dict__ for b in subcls.__mro__))
return NotImplemented # pragma: no cover


Expand Down
6 changes: 1 addition & 5 deletions src/coaster/utils/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ def markdown(
).convert(text)
if linkify:
output = linkify_processor(
output,
# types-bleach specifies `callbacks: Iterable[_Callback]`, but that
# _Callback has an incorrect definition for the `attrs` parameter
callbacks=LINKIFY_CALLBACKS, # type: ignore[arg-type]
skip_tags=LINKIFY_SKIP_TAGS,
output, callbacks=LINKIFY_CALLBACKS, skip_tags=LINKIFY_SKIP_TAGS
)
return Markup(output)
3 changes: 2 additions & 1 deletion src/coaster/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import re
import string
from collections.abc import Callable
from functools import partial
from html import unescape
from typing import Optional, Union
Expand Down Expand Up @@ -139,7 +140,7 @@ def dont_linkify_filenames(
return attrs


LINKIFY_CALLBACKS = [*DEFAULT_CALLBACKS, dont_linkify_filenames] # type: ignore[list-item]
LINKIFY_CALLBACKS: list[Callable] = [*DEFAULT_CALLBACKS, dont_linkify_filenames]


def sanitize_html(
Expand Down
2 changes: 1 addition & 1 deletion tests/coaster_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def task_factory(

def new_event_loop(self) -> asyncio.AbstractEventLoop:
loop = super().new_event_loop()
loop.set_task_factory(self.task_factory)
loop.set_task_factory(self.task_factory) # type: ignore[arg-type]
return loop


Expand Down
19 changes: 4 additions & 15 deletions tests/coaster_tests/sqlalchemy_annotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,23 @@ def test_annotation_in_annotations() -> None:
for model in (IdOnly, IdUuid, UuidOnly):
assert issubclass(model, ModelBase)
for annotation in (immutable, cached):
assert (
annotation.__name__ in model.__column_annotations__ # type: ignore[attr-defined]
)
assert annotation.__name__ in model.__column_annotations__


def test_attr_in_annotations() -> None:
"""Annotated attributes were discovered and documented."""
for model in (IdOnly, IdUuid, UuidOnly):
assert issubclass(model, ModelBase)
assert (
'is_immutable' in model.__column_annotations__['immutable'] # type: ignore[attr-defined]
)
assert (
'is_cached' in model.__column_annotations__['cached'] # type: ignore[attr-defined]
)
assert 'is_immutable' in model.__column_annotations__['immutable']
assert 'is_cached' in model.__column_annotations__['cached']


def test_base_attrs_in_annotations() -> None:
"""Annotations in the base class were also discovered and added to subclass."""
for model in (IdOnly, IdUuid, UuidOnly):
assert issubclass(model, ModelBase)
for attr in ('created_at', 'id'):
assert (
attr
in model.__column_annotations__[ # type: ignore[attr-defined]
'immutable'
]
)
assert attr in model.__column_annotations__['immutable']
assert 'uuid' in IdUuid.__column_annotations__['immutable']


Expand Down

0 comments on commit 3d3df8f

Please sign in to comment.