Skip to content

fix: expose lazy exports in dir() of eight more packages - #8374

Open
chrikrah wants to merge 1 commit into
google:mainfrom
chrikrah:fix-lazy-exports-dir
Open

chrikrah wants to merge 1 commit into
google:mainfrom
chrikrah:fix-lazy-exports-dir

Conversation

@chrikrah

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue

Problem

Eight packages with a hand-written __getattr__ lack __dir__, so dir() and the API reference miss 35 exports, Gemini among them.

Solution

Each gets the __dir__ that _lazy.accessors builds. None loads pandas, so no freezegun guard. As in plugins (9fd6b33), inspect.getmembers() and help() without the extra now raise the install hint for Claude and LiteLlm.

Testing Plan

Unit Tests

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
    • 49 labs/antigravity and release tests fail on 03725e8 too.
$ pytest -q tests/unittests/test_import_loading.py -k hand_written   # on 03725e8 plus this branch
8 passed, 30 deselected
$ pytest -q tests/unittests/test_import_loading.py -k hand_written   # same tests, the eight __init__.py files from 03725e8
8 failed, 30 deselected
$ pytest -q -n 4 tests/unittests   # Python 3.12.14, on 03725e8 plus this branch
49 failed, 26505 passed, 103 skipped, 63 xfailed, 2 xpassed, 44 subtests passed in 670.92s
$ PYTHONPATH=<03725e8 export>/src pytest -q <the 49 failed ids>   # same tests against the unchanged source
49 failed in 6.89s
$ pre-commit run --all-files
(all 14 hooks) Passed
$ mypy <the eight __init__.py files>   # mypy 2.4.1
Success: no issues found in 8 source files
# not run: the Sphinx build of the API reference

Manual End-to-End (E2E) Tests

The issue's repro now prints nothing.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
    • The same 49, as above.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.
    • N/A.

Additional context

I kept each __getattr__, since _lazy.accessors would drop four install hints. Is that the split you want?

google.adk.models, memory, artifacts, code_executors, apps,
tools.retrieval, a2a.agent and evaluation.simulation resolve their
exports in a hand-written module __getattr__ and define no __dir__, so
dir() omits 35 public names such as Gemini, Claude, App and
InMemoryMemoryService, and Sphinx autodoc leaves them out of the API
reference.

Give each package the __dir__ that _lazy.accessors builds,
sorted(set(globals()) | set(__all__)). Listing a name imports nothing.
None of these lazy targets imports pandas, so the freezegun guard in
google.adk.plugins is not needed here.

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazily exported classes such as Gemini and App are missing from dir() and the API reference

1 participant