Skip to content

[Gemini] Migrate all remaining uses of typing types with built-in equivalents#38334

Merged
jrmccluskey merged 15 commits intoapache:masterfrom
jrmccluskey:geminiBuiltins
May 5, 2026
Merged

[Gemini] Migrate all remaining uses of typing types with built-in equivalents#38334
jrmccluskey merged 15 commits intoapache:masterfrom
jrmccluskey:geminiBuiltins

Conversation

@jrmccluskey
Copy link
Copy Markdown
Contributor

@jrmccluskey jrmccluskey commented Apr 29, 2026

Finish migration off of typing types with PEP 585 built-in equivalents using a combination of ruff rule UP006 and Gemini. Also adds UP006 to the list of linting rules to automatically catch usages in deprecated typing types in PRs.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request completes the migration from typing module types to PEP 585 built-in equivalents throughout the codebase. This change improves code readability and aligns with modern Python standards.

Highlights

  • PEP 585 Migration: Migrated all remaining uses of typing types (e.g., List, Dict, Tuple) to their built-in equivalents (list, dict, tuple) across the codebase.
  • Code Cleanup: Removed unused imports resulting from the migration to built-in types.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates various files in the Apache Beam Python SDK to use modern Python type hinting syntax (e.g., replacing 'typing.List' with 'list', 'typing.Dict' with 'dict', and 'typing.Tuple' with 'tuple'). Additionally, it adds '# ruff: noqa: UP006' comments to several files to suppress linting warnings related to these changes. I have reviewed the comments regarding the placement of these ignore comments and have determined that they should be addressed to maintain consistent file formatting.

Comment thread sdks/python/apache_beam/typehints/arrow_type_compatibility.py Outdated
Comment thread sdks/python/apache_beam/typehints/batch_test.py Outdated
Comment thread sdks/python/apache_beam/typehints/decorators.py Outdated
Comment thread sdks/python/apache_beam/typehints/decorators_test.py Outdated
Comment thread sdks/python/apache_beam/typehints/native_type_compatibility.py Outdated
Comment thread sdks/python/apache_beam/typehints/schemas_test.py Outdated
Comment thread sdks/python/apache_beam/typehints/typecheck_test.py Outdated
Comment thread sdks/python/apache_beam/typehints/typed_pipeline_test.py Outdated
Comment thread sdks/python/apache_beam/typehints/typehints.py Outdated
Comment thread sdks/python/apache_beam/typehints/typehints_test.py Outdated
@jrmccluskey
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request performs a large-scale migration of type hints across the codebase to use PEP 585 built-in collection types (e.g., list[], dict[], tuple[]) instead of the typing module's deprecated aliases (List, Dict, Tuple). The changes cover numerous files, including SDK components, runners, and tests. The review comments point out that several files still contain '# ruff: noqa: UP006' comments, which suppress the linting rules that enforce this migration. If the migration is intended to be complete, these ignore comments should be removed and the code updated to use the built-in types.

Comment thread sdks/python/apache_beam/typehints/arrow_type_compatibility.py
Comment thread sdks/python/apache_beam/typehints/batch_test.py
Comment thread sdks/python/apache_beam/typehints/decorators.py
Comment thread sdks/python/apache_beam/typehints/decorators_test.py
Comment thread sdks/python/apache_beam/typehints/native_type_compatibility.py
Comment thread sdks/python/apache_beam/typehints/schemas_test.py
Comment thread sdks/python/apache_beam/typehints/typecheck_test.py
Comment thread sdks/python/apache_beam/typehints/typed_pipeline_test.py
Comment thread sdks/python/apache_beam/typehints/typehints.py
Comment thread sdks/python/apache_beam/typehints/typehints_test.py
@jrmccluskey jrmccluskey marked this pull request as ready for review May 1, 2026 14:42
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily updates the codebase to use built-in collection types (list, dict, tuple) instead of the deprecated typing module aliases (List, Dict, Tuple) in type hints, aligning with modern Python practices. This is supported by the addition of the 'UP006' rule to the Ruff configuration. Additionally, some unused imports were cleaned up. I have no further feedback.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Assigning reviewers:

R: @damccorm for label python.
R: @nielm for label spanner.
R: @mutianf for label bigtable.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@damccorm
Copy link
Copy Markdown
Contributor

damccorm commented May 4, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the codebase to use PEP 585 type hinting (e.g., using list[] and dict[] instead of typing.List and typing.Dict) across numerous files, including updates to ruff.toml to enforce this rule via UP006. Additionally, unused imports were removed, and a redundant import in sdks/python/apache_beam/runners/portability/fn_api_runner/worker_handlers.py was identified for removal.

from google.protobuf import message
from grpc import ServicerContext

from apache_beam.runners.portability.fn_api_runner.fn_runner import \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The import from grpc import ServicerContext is no longer used in the TYPE_CHECKING block. It should be removed to keep imports clean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the import is removed, although it actually shows up in some older-style comment annotations and should actually be restored.

tp = tp.__name__
else:
# Remove nested typing module name (like Optional)
tp = str(tp).replace("typing.", "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change? It seems odd to nest it in a large scale migration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's what is effectively a unit test for this functionality that exists strictly in the xlang integration test suites that was breaking on changing from the typing types to the built-ins, since it didn't know how to handle the built-ins. I felt like it was probably best to update the code to handle both cases here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see - this is valid because we're already in a branch with only builtins. I think this seems ok

Comment thread sdks/python/ruff.toml

[lint]
select = ["E9", "PL", "F821", "F822", "F823"]
select = ["E9", "PL", "F821", "F822", "F823", "UP006"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR mostly looks good to me, but its unclear to me how much value there is here - does this migration help us beyond minor standardization?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind taking it, but trying to understand the value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standardization as far as PEP 585 compliance, gets us off these types that are slated for removal from Python (although there's some waffling about when exactly this will happen, the earliest listed date was actually Python 3.9's EoL / 3.14's release.) This will also spare me, personally, from writing "use the built-in types and not the typing types" on every PR. Related to this point, I found that the gemini code assist was not particularly useful for identifying problems with type hints (the roughly 30 comments prior to your invocation all complained that I was making changes that were not compatible with Python 3.8 and 3.9.) So really this just pushes Beam towards best practices both within the repo and via linting rule all at once, rather than the module-by-module migration I had been doing in my spare time.

@jrmccluskey jrmccluskey merged commit dc7b5b0 into apache:master May 5, 2026
146 of 155 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants