Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import collections
import copy
import dataclasses
import functools
import json
import keyword
import re
Expand Down Expand Up @@ -1277,20 +1276,16 @@ def _to_regex(self, path_template: str) -> Pattern:
"""
return re.compile(f"^{self._convert_to_regex(path_template)}$")

# Use caching to avoid repeated computation
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2161):
# Use `@functools.cache` instead of `@functools.lru_cache` once python 3.8 is dropped.
# https://docs.python.org/3/library/functools.html#functools.cache
@functools.lru_cache(maxsize=None)
def to_regex(self) -> Pattern:
# Use caching to avoid repeated computation.
@utils.cached_property
def _regex(self) -> Pattern:
return self._to_regex(self.path_template)

@property
# Use caching to avoid repeated computation
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2161):
# Use `@functools.cache` instead of `@functools.lru_cache` once python 3.8 is dropped.
# https://docs.python.org/3/library/functools.html#functools.cache
@functools.lru_cache(maxsize=None)
def to_regex(self) -> Pattern:
return self._regex

# Use caching to avoid repeated computation.
@utils.cached_property
def key(self) -> Union[str, None]:
if self.path_template == "":
return self.field
Expand Down