Skip to content

Conversation

cepedus
Copy link

@cepedus cepedus commented Jan 18, 2025

This PR types the decorators _connection_factory and _async_connection_factory, avoiding the loss of types when using connect and connect_async by client projects.

Minimal example to verify correctness (Python 3.8):

from typing import TYPE_CHECKING, Any, Dict import oracledb def get_connection() -> oracledb.Connection: conn_params: Dict[str, Any] = {} return oracledb.connect(**conn_params) def get_async_connection() -> oracledb.AsyncConnection: conn_params: Dict[str, Any] = {} return oracledb.connect_async(**conn_params) if TYPE_CHECKING: reveal_type(oracledb.connect) reveal_type(oracledb.connect_async)

Gives as output using mypy --strict:

sample_connection.py:17: note: Revealed type is "def (*Any, **Any) -> oracledb.connection.Connection" sample_connection.py:18: note: Revealed type is "def (*Any, **Any) -> oracledb.connection.AsyncConnection" Success: no issues found in 1 source file

Closes #438

Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jan 18, 2025
Signed-off-by: Martin Cepeda <martin.cepedavega@gmail.com>
@cepedus cepedus force-pushed the 438-connection-typing branch from 2dde08b to b0dcf08 Compare January 18, 2025 20:53
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Jan 18, 2025
@cjbj
Copy link
Member

cjbj commented Jan 21, 2025

Thanks - we'll take a look.

@cepedus
Copy link
Author

cepedus commented Feb 13, 2025

@cjbj up for reviews :)

@cjbj
Copy link
Member

cjbj commented Feb 13, 2025

@cepedus has it been three weeks? Thanks for the nudge. We will take a look and see if we can get this into the next release.

anthony-tuininga added a commit that referenced this pull request Feb 18, 2025
anthony-tuininga added a commit that referenced this pull request Feb 18, 2025
@anthony-tuininga
Copy link
Member

@cepedus, I split the PR into two parts: one that was simple formatting changes and the other that implemented the new typing definitions. I also enhanced that one further to handle not just connections but also connection pools. Based on that I am going to close this PR. Thanks for showing the way forward here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
3 participants