Skip to content

Commit

Permalink
Improve IDE type hinting of methdtools.lru_cache in Task SDK client (a…
Browse files Browse the repository at this point in the history
…pache#44152)

mypy doesn't check the type of double decorators (hence why we still need the
ignore misc) but pyright does, and methodtools doesn't have type hints, which
lead to it not being able to tell what type of `client.task_instances` was
  • Loading branch information
ashb authored Nov 18, 2024
1 parent 6faa720 commit 2bd701a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions task_sdk/src/airflow/sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import sys
import uuid
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, TypeVar

import httpx
import methodtools
import msgspec
import structlog
from pydantic import BaseModel
Expand All @@ -42,6 +41,19 @@
if TYPE_CHECKING:
from datetime import datetime

from airflow.typing_compat import ParamSpec

P = ParamSpec("P")
T = TypeVar("T")

# # methodtools doesn't have typestubs, so give a stub
def lru_cache(maxsize: int | None = 128):
def wrapper(f):
return f

return wrapper
else:
from methodtools import lru_cache

log = structlog.get_logger(logger_name=__name__)

Expand Down Expand Up @@ -163,13 +175,13 @@ def __init__(self, *, base_url: str | None, dry_run: bool = False, token: str, *
# methods on one object prefixed with the object type (`.task_instances.update` rather than
# `task_instance_update` etc.)

@methodtools.lru_cache() # type: ignore[misc]
@lru_cache() # type: ignore[misc]
@property
def task_instances(self) -> TaskInstanceOperations:
"""Operations related to TaskInstances."""
return TaskInstanceOperations(self)

@methodtools.lru_cache() # type: ignore[misc]
@lru_cache() # type: ignore[misc]
@property
def connections(self) -> ConnectionOperations:
"""Operations related to TaskInstances."""
Expand Down

0 comments on commit 2bd701a

Please sign in to comment.