Skip to content

Commit 36a47bd

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
fix: Resolve vertexai.types against agentplatform.types
PiperOrigin-RevId: 983997505
1 parent 75ecb3b commit 36a47bd

5 files changed

Lines changed: 10 additions & 229 deletions

File tree

‎agentplatform/__init__.py‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,8 @@ def __getattr__(name): # type: ignore[no-untyped-def]
5454
global _genai_types
5555
if _genai_types is None:
5656
_genai_types = importlib.import_module("._genai.types", __name__)
57-
# `types` is an alias for `._genai.types` rather than a real submodule,
58-
# so register it to keep
59-
# `from agentplatform.types import TypeName`
60-
# working without a prior attribute access. Spell it the google3 way:
61-
# Copybara rewrites that prefix in both directions, and the external
62-
# spelling fails its reversibility check. This key was `vertexai.types`,
63-
# which both misnamed this package's own alias and shadowed the real
64-
# `vertexai.types` module.
65-
types_module_name = f"{__name__}.types"
66-
if types_module_name not in sys.modules:
67-
sys.modules[types_module_name] = _genai_types
57+
if "vertexai.types" not in sys.modules:
58+
sys.modules["vertexai.types"] = _genai_types
6859
return _genai_types
6960

7061
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

‎tests/unit/vertexai/test_autorater_yaml.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ def setup_method(self):
160160
vertexai.init(
161161
project=_TEST_PROJECT,
162162
location=_TEST_LOCATION,
163-
# Set explicitly rather than inherited. `init` leaves an already
164-
# configured credential in place, and test_extensions installs a
165-
# `Mock(spec=AnonymousCredentials)` globally that it never resets;
166-
# `_upload_string_to_gcs` then hands `global_config.credentials`
167-
# to `storage.Client`, which rejects the Mock's `universe_domain`.
168-
# Whether that leak reaches this module depends on how
169-
# `--dist=loadscope` happens to assign modules to xdist workers.
170-
credentials=auth_credentials.AnonymousCredentials(),
171163
)
172164

173165
def teardown_method(self):

‎tests/unit/vertexai/test_types_alias.py‎

Lines changed: 0 additions & 122 deletions
This file was deleted.

‎vertexai/__init__.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""The vertexai module."""
1616

1717
import importlib
18+
import sys
1819

1920
from google.cloud.aiplatform import version as aiplatform_version
2021

@@ -23,6 +24,7 @@
2324
from google.cloud.aiplatform import init
2425

2526
_genai_client = None
27+
_genai_types = None
2628

2729

2830
def __getattr__(name): # type: ignore[no-untyped-def]
@@ -43,10 +45,12 @@ def __getattr__(name): # type: ignore[no-untyped-def]
4345
return getattr(_genai_client, name)
4446

4547
if name == "types":
46-
# `types` is a real submodule that resolves against
47-
# `agentplatform.types`, so importing it also binds it as an attribute
48-
# here and this runs only once.
49-
return importlib.import_module(".types", __name__)
48+
global _genai_types
49+
if _genai_types is None:
50+
_genai_types = importlib.import_module("._genai.types", __name__)
51+
if "vertexai.types" not in sys.modules:
52+
sys.modules["vertexai.types"] = _genai_types
53+
return _genai_types
5054

5155
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
5256

‎vertexai/types.py‎

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)