Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect & connect_async typing #438

Open
cepedus opened this issue Jan 3, 2025 · 4 comments
Open

connect & connect_async typing #438

cepedus opened this issue Jan 3, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@cepedus
Copy link

cepedus commented Jan 3, 2025

Hello, when using the methods connect or connect_async, the return types are lost because of the untyped decorators _async_connection_factory and _connection_factory.

The fix includes the adding of a TypeVar and a ParamSpec to make them coherent with the wrapped callables. This will be usable for all platforms and Python versions >=3.8, using typing_extensions for python < 3.10.

I can tackle the issue if needed :)

@cepedus cepedus added the enhancement New feature or request label Jan 3, 2025
@anthony-tuininga
Copy link
Member

Thanks for the details. I'll let @cjbj comment on whether he would like your assistance with this issue. Can you, however, share some details on how the current code fails? A quick test with mypy doesn't reveal any concerns, so I must be missing something!

@cjbj
Copy link
Member

cjbj commented Jan 4, 2025

Two points:

  • We don't want to be dependent any not absolutely needed modules, so I'm not in favor of using typing_extensions. This is for compliance and risk reasons. If this means that only 3.10+ have this feature, then we can live with that.
  • Any contribution will need the OCA signed first.

@cepedus
Copy link
Author

cepedus commented Jan 4, 2025

Hello @anthony-tuininga, here is a minimal script:

from typing import TYPE_CHECKING, Any

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)

The output of mypy on Python 3.10 is the following:

note: Revealed type is "Any"
note: Revealed type is "Any"

Using mypy --strict on Python 3.10 we get the error itself on the return statement lines:

error: Returning Any from function declared to return "Connection"  [no-any-return]
error: Returning Any from function declared to return "AsyncConnection"  [no-any-return]

@cjbj I have just signed the OCA, it is marked as "Under review" :)

@cepedus
Copy link
Author

cepedus commented Jan 4, 2025

Actually, testing in local there is no need for ParamSpec. The improvement can be done for all supported Python versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants