Skip to content

Commit

Permalink
Use methodtools.lru_cache instead of functools.lru_cache in class…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
Taragolis committed Feb 29, 2024
1 parent 0b1cad5 commit bab6130
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ repos:
files: ^dev/breeze/.*$
pass_filenames: false
require_serial: true
additional_dependencies: ['click', 'rich>=12.4.4', 'pyyaml']
additional_dependencies: ['click', 'rich>=12.4.4', 'pyyaml', 'methodtools']
- id: check-system-tests-present
name: Check if system tests have required segments of code
entry: ./scripts/ci/pre_commit/pre_commit_check_system_tests.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from __future__ import annotations

import asyncio
from functools import lru_cache
from typing import TYPE_CHECKING, Sequence

import methodtools
from google.api_core.client_options import ClientOptions
from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
from google.cloud.aiplatform import CustomJob, HyperparameterTuningJob, gapic, hyperparameter_tuning
Expand Down Expand Up @@ -446,7 +446,7 @@ def __init__(
**kwargs,
)

@lru_cache
@methodtools.lru_cache(maxsize=None)
def get_job_service_client(self, region: str | None = None) -> JobServiceAsyncClient:
"""
Retrieve Vertex AI async client.
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/google/common/hooks/base_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import google.auth.credentials
import google.oauth2.service_account
import google_auth_httplib2
import methodtools
import requests
import tenacity
from asgiref.sync import sync_to_async
Expand Down Expand Up @@ -316,7 +317,7 @@ def _get_access_token(self) -> str:
credentials.refresh(auth_req)
return credentials.token

@functools.lru_cache(maxsize=None)
@methodtools.lru_cache(maxsize=None)
def _get_credentials_email(self) -> str:
"""
Return the email address associated with the currently logged in account.
Expand Down
1 change: 1 addition & 0 deletions airflow/providers/google/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ dependencies:
- httpx
- json-merge-patch>=0.2
- looker-sdk>=22.2.0
- methodtools>=0.4.7
- pandas-gbq
# In pandas 2.2 minimal version of the sqlalchemy is 2.0
# https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#increased-minimum-versions-for-dependencies
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ PLEASE DO NOT MODIFY THE HASH BELOW! IT IS AUTOMATICALLY UPDATED BY PRE-COMMIT.

---------------------------------------------------------------------------------------------------------

Package config hash: e2db123fd25e40b515520fb9f6ed32a601fe85e6a22b9845343bc5c81e5785b472527ed3bf6d07521c512d2222f99877a1ce1911ac504a3a6af7b7866aa674cc
Package config hash: 745191d7db32d0d0304f9ccc3b26b35d0f9417857b386012474bf5dc1f611a6f375a88a1f65f27782a6a8e018b50f11979df03a2d48ef3b01c2cfe27918b4dd7

---------------------------------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions dev/breeze/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies = [
"inputimeout>=1.0.4",
"jinja2>=3.1.0",
"jsonschema>=4.19.1",
"methodtools>=0.4.7",
"packaging>=23.2",
"pipx>=1.4.1",
"pre-commit>=3.5.0",
Expand Down
6 changes: 4 additions & 2 deletions dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import re
import sys
from enum import Enum
from functools import cached_property, lru_cache
from functools import cached_property
from typing import Any, Dict, List, TypeVar

import methodtools

from airflow_breeze.branch_defaults import AIRFLOW_BRANCH, DEFAULT_AIRFLOW_CONSTRAINTS_BRANCH
from airflow_breeze.global_constants import (
ALL_PYTHON_MAJOR_MINOR_VERSIONS,
Expand Down Expand Up @@ -540,7 +542,7 @@ def _exclude_files_with_regexps(self, matched_files, exclude_regexps):
if file in matched_files:
matched_files.remove(file)

@lru_cache(maxsize=None)
@methodtools.lru_cache(maxsize=None)
def _matching_files(
self, match_group: T, match_dict: dict[T, list[str]], exclude_dict: dict[T, list[str]]
) -> list[str]:
Expand Down
1 change: 1 addition & 0 deletions generated/provider_dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@
"httpx",
"json-merge-patch>=0.2",
"looker-sdk>=22.2.0",
"methodtools>=0.4.7",
"pandas-gbq",
"pandas>=1.2.5,<2.2",
"proto-plus>=1.19.6",
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ google = [ # source: airflow/providers/google/provider.yaml
"httpx",
"json-merge-patch>=0.2",
"looker-sdk>=22.2.0",
"methodtools>=0.4.7",
"pandas-gbq",
"pandas>=1.2.5,<2.2",
"proto-plus>=1.19.6",
Expand Down Expand Up @@ -1326,6 +1327,7 @@ extend-select = [
"TID253", # Ban certain modules from being imported at module level
"ISC", # Checks for implicit literal string concatenation (auto-fixable)
"B006", # Checks for uses of mutable objects as function argument defaults.
"B019", # Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
"PT001",
"PT003",
"PT009",
Expand Down

0 comments on commit bab6130

Please sign in to comment.