You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "jrmccluskey (via GitHub)" <gi...@apache.org> on 2026/04/29 18:59:50 UTC

[PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

jrmccluskey opened a new pull request, #38331:
URL: https://github.com/apache/beam/pull/38331

   Remove an effective no-op Python version check, clean up references to pre-PEP 585 types in the python apache_beam/internal directory
   
   ------------------------
   
   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](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](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](https://github.com/apache/beam/actions/workflows/build_wheels.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/actions/workflows/python_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/actions/workflows/java_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/actions/workflows/go_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey closed pull request #38331: Clean up unnecessary Python version check, remove old typing types from internal directory
URL: https://github.com/apache/beam/pull/38331


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38331:
URL: https://github.com/apache/beam/pull/38331#discussion_r3163489772


##########
sdks/python/apache_beam/internal/dill_pickler.py:
##########
@@ -315,7 +313,7 @@ def save_module(pickler, obj):
   # Pickle module dictionaries (commonly found in lambda's globals)
   # by referencing their module.
   old_save_module_dict = dill.dill.save_module_dict
-  known_module_dicts: Dict[int, Tuple[types.ModuleType, Dict[str, Any]]] = {}
+  known_module_dicts: dict[int, tuple[types.ModuleType, dict[str, Any]]] = {}

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using built-in generics like `dict[...]` and `tuple[...]` (PEP 585) in type annotations will cause a `TypeError` at runtime on Python 3.8 unless `from __future__ import annotations` is present at the top of the file. Since Apache Beam still supports Python 3.8, please ensure the future import is present or continue using `typing.Dict` and `typing.Tuple`.



##########
sdks/python/apache_beam/internal/dill_pickler.py:
##########
@@ -50,7 +48,7 @@
 
 settings = {'dill_byref': None}
 
-patch_save_code = sys.version_info >= (3, 10) and dill.__version__ == "0.3.1.1"
+patch_save_code = dill.__version__ == "0.3.1.1"

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The removal of the `sys.version_info >= (3, 10)` check is likely a regression. This monkey-patch was specifically introduced to fix `dill 0.3.1.1` on Python 3.10+, where `types.CodeType` underwent significant changes (e.g., the introduction of `co_linetable`). On Python 3.8 and 3.9, `dill 0.3.1.1` works correctly without this patch. Applying this 3.10-specific patch on older Python versions will likely cause a `TypeError` due to incompatible constructor arguments for code objects. Since Apache Beam still supports Python 3.8 and 3.9, this version check should be retained.
   
   ```suggestion
   patch_save_code = sys.version_info >= (3, 10) and dill.__version__ == "0.3.1.1"
   ```



##########
sdks/python/apache_beam/internal/metrics/metric.py:
##########
@@ -59,7 +57,7 @@ class Metrics(object):
   @staticmethod
   def counter(
       urn: str,
-      labels: Optional[Dict[str, str]] = None,
+      labels: Optional[dict[str, str]] = None,

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using `dict[str, str]` as a type hint will cause a `TypeError` on Python 3.8 unless `from __future__ import annotations` is present at the top of the file. Without the future import, built-in types are not subscriptable in Python 3.8.



##########
sdks/python/apache_beam/internal/util.py:
##########
@@ -68,9 +64,9 @@ def __hash__(self):
 
 def remove_objects_from_args(
     args: Iterable[Any],
-    kwargs: Dict[str, Any],
-    pvalue_class: Union[Type[T], Tuple[Type[T], ...]]
-) -> Tuple[List[Any], Dict[str, Any], List[T]]:
+    kwargs: dict[str, Any],
+    pvalue_class: Union[type[T], tuple[type[T], ...]]
+) -> tuple[list[Any], dict[str, Any], list[T]]:

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   This change breaks compatibility with Python 3.8. Built-in generics like `dict[...]` and `tuple[...]` (PEP 585), as well as subscripting `collections.abc.Iterable`, are only supported in Python 3.9+. For Python 3.8 compatibility, these require `from __future__ import annotations` to be present at the top of the file. Additionally, if these types are evaluated at runtime (e.g., via `typing.get_type_hints()`), they will still cause a `TypeError` on Python 3.8 even with the future import.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on PR #38331:
URL: https://github.com/apache/beam/pull/38331#issuecomment-4346871987

   Going to do a bigger LLM-driven fix here, closing


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on code in PR #38331:
URL: https://github.com/apache/beam/pull/38331#discussion_r3163497268


##########
sdks/python/apache_beam/internal/dill_pickler.py:
##########
@@ -50,7 +48,7 @@
 
 settings = {'dill_byref': None}
 
-patch_save_code = sys.version_info >= (3, 10) and dill.__version__ == "0.3.1.1"
+patch_save_code = dill.__version__ == "0.3.1.1"

Review Comment:
   Beam does not support any Python version older than 3.10.



##########
sdks/python/apache_beam/internal/dill_pickler.py:
##########
@@ -315,7 +313,7 @@ def save_module(pickler, obj):
   # Pickle module dictionaries (commonly found in lambda's globals)
   # by referencing their module.
   old_save_module_dict = dill.dill.save_module_dict
-  known_module_dicts: Dict[int, Tuple[types.ModuleType, Dict[str, Any]]] = {}
+  known_module_dicts: dict[int, tuple[types.ModuleType, dict[str, Any]]] = {}

Review Comment:
   Beam does not support any Python version older than 3.10.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on code in PR #38331:
URL: https://github.com/apache/beam/pull/38331#discussion_r3163498548


##########
sdks/python/apache_beam/internal/metrics/metric.py:
##########
@@ -59,7 +57,7 @@ class Metrics(object):
   @staticmethod
   def counter(
       urn: str,
-      labels: Optional[Dict[str, str]] = None,
+      labels: Optional[dict[str, str]] = None,

Review Comment:
   Beam does not support any Python version older than 3.10.



##########
sdks/python/apache_beam/internal/util.py:
##########
@@ -68,9 +64,9 @@ def __hash__(self):
 
 def remove_objects_from_args(
     args: Iterable[Any],
-    kwargs: Dict[str, Any],
-    pvalue_class: Union[Type[T], Tuple[Type[T], ...]]
-) -> Tuple[List[Any], Dict[str, Any], List[T]]:
+    kwargs: dict[str, Any],
+    pvalue_class: Union[type[T], tuple[type[T], ...]]
+) -> tuple[list[Any], dict[str, Any], list[T]]:

Review Comment:
   Beam does not support any Python version older than 3.10.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38331:
URL: https://github.com/apache/beam/pull/38331#issuecomment-4346700065

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! 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 focuses on cleaning up the internal codebase by removing redundant version checks and modernizing type annotations. By adopting PEP 585 standards, the code becomes more idiomatic and leverages native Python type support, improving maintainability and reducing reliance on the typing module for standard collection types.
   
   ### Highlights
   
   * **Python Version Check Cleanup**: Removed an unnecessary Python version check in the dill pickler logic that was effectively a no-op.
   * **PEP 585 Type Modernization**: Updated internal modules to use built-in collection types (e.g., dict, list, tuple) instead of the deprecated typing module equivalents, in accordance with PEP 585.
   
   🧠 **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](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   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.
   
   <b>Customization</b>
   
   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](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Clean up unnecessary Python version check, remove old typing types from internal directory [beam]

Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on PR #38331:
URL: https://github.com/apache/beam/pull/38331#issuecomment-4346732240

   The Gemini code review bot seems to think that Beam supports Python 3.8 and 3.9. I am also not particularly pleased that it is auto-reviewing code by default again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org