Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit db204f6

Browse files
committed
fix formatting
1 parent fbad3e1 commit db204f6

4 files changed

Lines changed: 13 additions & 27 deletions

File tree

gapic/cli/generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from gapic.utils import Options
2626
from gapic.utils.cache import generation_cache_context
2727

28+
2829
@click.command()
2930
@click.option(
3031
"--request",

gapic/schema/metadata.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ def resolve(self, selector: str) -> str:
361361
return selector
362362

363363
@cached_proto_context
364-
def with_context(
365-
self, *, collisions: Set[str]
366-
) -> "Address":
364+
def with_context(self, *, collisions: Set[str]) -> "Address":
367365
"""Return a derivative of this address with the provided context.
368366
369367
This method is used to address naming collisions. The returned
@@ -403,9 +401,7 @@ def doc(self):
403401
return ""
404402

405403
@cached_proto_context
406-
def with_context(
407-
self, *, collisions: Set[str]
408-
) -> "Metadata":
404+
def with_context(self, *, collisions: Set[str]) -> "Metadata":
409405
"""Return a derivative of this metadata with the provided context.
410406
411407
This method is used to address naming collisions. The returned
@@ -415,9 +411,7 @@ def with_context(
415411
return (
416412
dataclasses.replace(
417413
self,
418-
address=self.address.with_context(
419-
collisions=collisions
420-
),
414+
address=self.address.with_context(collisions=collisions),
421415
)
422416
if collisions and collisions != self.address.collisions
423417
else self

gapic/schema/wrappers.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,7 @@ def with_context(
437437
if self.message
438438
else None
439439
),
440-
enum=(
441-
self.enum.with_context(
442-
collisions=collisions
443-
)
444-
if self.enum
445-
else None
446-
),
440+
enum=(self.enum.with_context(collisions=collisions) if self.enum else None),
447441
meta=self.meta.with_context(
448442
collisions=collisions,
449443
),
@@ -862,9 +856,7 @@ def with_context(
862856
)
863857
for k, v in self.nested_messages.items()
864858
},
865-
meta=self.meta.with_context(
866-
collisions=collisions
867-
),
859+
meta=self.meta.with_context(collisions=collisions),
868860
)
869861

870862
def add_to_address_allowlist(
@@ -968,9 +960,7 @@ def with_context(
968960
return (
969961
dataclasses.replace(
970962
self,
971-
meta=self.meta.with_context(
972-
collisions=collisions
973-
),
963+
meta=self.meta.with_context(collisions=collisions),
974964
)
975965
if collisions
976966
else self

gapic/utils/cache.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def inner(self):
4747

4848
return property(inner)
4949

50+
5051
# 1. The ContextVar (Default is None)
5152
# This replaces threading.local with the async-safe standard.
5253
generation_cache: ContextVar[Optional[Dict[Any, Any]]] = ContextVar(
@@ -56,10 +57,11 @@ def inner(self):
5657
# Optimization: Bind .get for speed
5758
_get_cache = generation_cache.get
5859

60+
5961
@contextlib.contextmanager
6062
def generation_cache_context():
6163
"""Context manager to explicitly manage the cache lifecycle.
62-
64+
6365
Usage:
6466
with generation_cache_context():
6567
# Cache is active (fast)
@@ -74,6 +76,7 @@ def generation_cache_context():
7476
# This allows the dictionary to be garbage collected.
7577
generation_cache.reset(token)
7678

79+
7780
def cached_proto_context(func):
7881
"""Decorator to memoize with_context calls based on self and collisions."""
7982

@@ -83,7 +86,7 @@ def wrapper(self, *, collisions, **kwargs):
8386

8487
context_cache = _get_cache()
8588
if context_cache is None:
86-
raise RuntimeError(
89+
raise RuntimeError(
8790
f"Cache MISSING! {func.__name__} called on {type(self).__name__} outside of context manager."
8891
)
8992

@@ -97,9 +100,7 @@ def wrapper(self, *, collisions, **kwargs):
97100

98101
# 4. Execute the actual function
99102
# We ensure context_cache is passed down to the recursive calls
100-
result = func(
101-
self, collisions=collisions, **kwargs
102-
)
103+
result = func(self, collisions=collisions, **kwargs)
103104

104105
# 5. Update Cache
105106
context_cache[key] = result

0 commit comments

Comments
 (0)