You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "ittuann (via GitHub)" <gi...@apache.org> on 2026/06/24 05:23:42 UTC

[PR] feat: modernize Python Client syntax (PEP 585, PEP 604)

ittuann opened a new pull request, #4628:
URL: https://github.com/apache/streampipes/pull/4628

   <!--
     ~ Licensed to the Apache Software Foundation (ASF) under one or more
     ~ contributor license agreements.  See the NOTICE file distributed with
     ~ this work for additional information regarding copyright ownership.
     ~ The ASF licenses this file to You under the Apache License, Version 2.0
     ~ (the "License"); you may not use this file except in compliance with
     ~ the License.  You may obtain a copy of the License at
     ~
     ~    http://www.apache.org/licenses/LICENSE-2.0
     ~
     ~ Unless required by applicable law or agreed to in writing, software
     ~ distributed under the License is distributed on an "AS IS" BASIS,
     ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     ~ See the License for the specific language governing permissions and
     ~ limitations under the License.
     ~
     -->
   
     <!--
   Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/community/get-involved/
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar.
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### Purpose
   <!--
   Please clarify what changes you are proposing and describe how those changes will address the issue.
   Furthermore, describe potential consequences the changes might have.
   -->
   This PR modernizes our syntax and type hinting to align with newer Python standards.
   Part of #4617
   
   - Implement [PEP 585](https://peps.python.org/pep-0585/#implementation):
     - Migrate abstract base classes from the `typing` module to `collections.abc`, which was deprecated starting from Python 3.9 (e.g., using `collections.abc.Sequence` instead of `typing.Sequence`, and similarly for `Callable` and `AsyncIterator`).
     - Use standard collection types instead of their typing counterparts (e.g., using `dict` instead of `typing.Dict`)
   - Implement [PEP 604](https://peps.python.org/pep-0604/):
     - Replace `typing.Optional` with the modern `|` operator, as it is the recommended syntax starting from Python 3.10 (e.g., using `str | None` instead of `typing.Optional[str]`).
     - Replace `typing.Union` with the modern `|` operator (e.g., using `X | Y` instead of `typing.Union[X, Y]`).
   
   These updates will clean up the codebase and improve readability, and ensure we adhere to modern Python best practices.
   
   
   ### Remarks
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): <yes/no>
   no
   PR introduces (a) deprecation(s): <yes/no>
   no


-- 
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: dev-unsubscribe@streampipes.apache.org

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


Re: [PR] feat: modernize Python Client syntax (PEP 585, PEP 604)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti merged PR #4628:
URL: https://github.com/apache/streampipes/pull/4628


-- 
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: dev-unsubscribe@streampipes.apache.org

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


Re: [PR] feat: modernize Python Client syntax (PEP 585, PEP 604)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4628:
URL: https://github.com/apache/streampipes/pull/4628#discussion_r3464749002


##########
streampipes-client-python/streampipes/endpoint/api/data_lake_measure.py:
##########
@@ -339,14 +339,14 @@ def _container_cls(self) -> Type[ResourceContainer]:
         return DataLakeMeasures
 
     @property
-    def _relative_api_path(self) -> Tuple[str, ...]:
+    def _relative_api_path(self) -> tuple[str, ...]:
         """Defines the relative api path to the DataLakeMeasurement endpoint.
         Each path within the URL is defined as an own string.
         """
 
         return "api", "v4", "datalake", "measurements"
 
-    def get(self, identifier: str, **kwargs: Optional[Dict[str, Any]]) -> QueryResult:
+    def get(self, identifier: str, **kwargs: dict[str, Any] | None) -> QueryResult:

Review Comment:
   `**kwargs` annotations apply to the *values* of keyword arguments, not to the kwargs dict itself. Also, `kwargs` is always a dict at runtime (never `None`).
   
   To express “any keyword query params”, annotate as `**kwargs: Any` (or a union of allowed value types).



##########
streampipes-client-python/streampipes/endpoint/api/data_lake_measure.py:
##########
@@ -81,17 +81,17 @@ class MeasurementGetQueryConfig(BaseModel):
 
     model_config = ConfigDict(extra="forbid", populate_by_name=True)
 
-    columns: Optional[str] = Field(default=None, pattern=_regex_comma_separated_string)
-    end_date: Optional[StrictInt] = Field(default=None, alias="endDate")
-    limit: Optional[int] = Field(ge=1, default=1000)
-    offset: Optional[int] = Field(default=None, ge=0)
-    order: Optional[Literal["ASC", "DESC"]] = None
-    page_no: Optional[int] = Field(default=None, alias="page", ge=1)
-    start_date: Optional[StrictInt] = Field(default=None, alias="startDate")
+    columns: str | None = Field(default=None, pattern=_regex_comma_separated_string)
+    end_date: StrictInt | None = Field(default=None, alias="endDate")
+    limit: int | None = Field(ge=1, default=1000)
+    offset: int | None = Field(default=None, ge=0)
+    order: Literal["ASC", "DESC"] | None = None
+    page_no: int | None = Field(default=None, alias="page", ge=1)
+    start_date: StrictInt | None = Field(default=None, alias="startDate")
 
     @field_validator("columns", mode="before")
     @classmethod
-    def _convert_to_comma_separated_string(cls, value: Any) -> Optional[str]:
+    def _convert_to_comma_separated_string(cls, value: Any) -> str | None:
         """Pydantic validator to convert a list to a comma separated string.
         This is necessary for the StreamPipes API.

Review Comment:
   The `columns` validator only accepts `list` and raises for a `str`, but the endpoint examples below use `columns='density'`. With the current implementation, passing a comma-separated string (already valid per docs) fails at runtime.
   
   Consider allowing both `str` (pass-through) and `list[str]` (join).



-- 
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: dev-unsubscribe@streampipes.apache.org

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


Re: [PR] feat: modernize Python Client syntax (PEP 585, PEP 604)

Posted by "ittuann (via GitHub)" <gi...@apache.org>.
ittuann commented on PR #4628:
URL: https://github.com/apache/streampipes/pull/4628#issuecomment-4786288397

   By the way, quick ask, Is the Copilot Code Review expected to run automatically here?
   
   I have disabled Automatic Copilot Code Review on my personal account settings.
   
   I know repository Rules might be able to Automatic Request Copilot Code Review, but I haven't encountered this on my previous PRs, and other PRs didn't trigger it either, so I just wanted to check if this is the intended behavior.
   


-- 
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: dev-unsubscribe@streampipes.apache.org

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


Re: [PR] feat: modernize Python Client syntax (PEP 585, PEP 604)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on PR #4628:
URL: https://github.com/apache/streampipes/pull/4628#issuecomment-4787215449

   @ittuann thanks for taking that task! 🙏 
   
   Copilot review has been enabled recently: 
   
   https://github.com/apache/streampipes/pull/4513


-- 
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: dev-unsubscribe@streampipes.apache.org

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