dwreeves opened a new pull request, #31846:
URL: https://github.com/apache/airflow/pull/31846

   # Overview
   
   The `DbApiHook.run` method has incredibly complex typing, which is currently 
reduced to just the following:
   
   ```python
       def run(
           self,
           sql: str | Iterable[str],
           autocommit: bool = False,
           parameters: Iterable | Mapping | None = None,
           handler: Callable | None = None,
           split_statements: bool = True,
           return_last: bool = True,
       ) -> Any | list[Any] | None:
   ```
   
   This is incomplete typing for a few reasons:
   
   - Some of the `bool`s in the kwargs determine the return type.
   - Whether the `handler` is `None` determines whether the return type is 
`None`.
   - The return type of the `handler` is generic and determines the return type 
of the `run` method.
   
   Addressing the first bullet point would be a bit of work, and would add a 
lot of complicated typing to each provider hook.
   
   But I figured addressing the 2nd and 3rd bullet points was easy and takes 
just 2 overloads. This alone helps vastly improve the typing of of the 
`DbApiHook.run` method with a minimal amount of added annotation complexity.
   
   # Misc.
   
   - I do not anticipate that this should cause any backwards compatibility 
concerns except for users who meet all the following criteria: (1) they are 
relying on the `DbiApiHook` directly, (2) they are using mypy or another type 
checker, and (3) they had type checking issues that were not being properly 
flagged before due to the less precise typing.
   - I did not open an issue because the issues template for feature requests 
says:
       > Features should be small improvements that do not dramatically change 
Airflow assumptions. Note, that in this case you do not even need to create an 
issue if you have a code change ready to submit! You can open [Pull 
Request](https://github.com/apache/airflow/pulls) immediately instead.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to