Skip to content

[1.7] Any in decorated function with TypeVar #16482

Closed as not planned
Closed as not planned
@Dreamsorcerer

Description

@Dreamsorcerer

Bug Report

This looks different to me, but could maybe be the same as #16481.

aiohttp_admin/security.py:18:1: error: Type of decorated function contains type
"Any" ("_lru_cache_wrapper[TypeAdapter[Any]]")  [misc]
    def _get_schema(t: Type[_T]) -> TypeAdapter[_T]:
    ^
aiohttp_admin/security.py:24:5: error: Returning Any from function declared to
return "_T"  [no-any-return]
        return _get_schema(t).validate_python(value)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 20 source files)

https://github.com/aio-libs/aiohttp-admin/actions/runs/6845242250/job/18610174092?pr=810

To Reproduce

from collections.abc import Hashable
from functools import lru_cache
from typing import Type, TypeVar

from pydantic import TypeAdapter

_T = TypeVar("_T", bound=Hashable)


@lru_cache
def _get_schema(t: Type[_T]) -> TypeAdapter[_T]:
    return TypeAdapter(t)


def check(t: Type[_T], value: object) -> _T:
    """Validate value is of static type t."""
    return _get_schema(t).validate_python(value)

Also at aio-libs/aiohttp-admin#810

Or, without pydantic:

from collections.abc import Hashable
from functools import lru_cache
from typing import Type, TypeVar

_T = TypeVar("_T", bound=Hashable)


@lru_cache
def _get_schema(t: Type[_T]) -> list[_T]:
    return []


def check(t: Type[_T], value: object) -> _T:
    """Validate value is of static type t."""
    return _get_schema(t)[0]

Expected Behavior

There shouldn't be Any in these functions.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions