Skip to content

Update type annotations in connection.py#429

Open
RA80533 wants to merge 11 commits into
aio-libs:masterfrom
RA80533:chore/typing/connection
Open

Update type annotations in connection.py#429
RA80533 wants to merge 11 commits into
aio-libs:masterfrom
RA80533:chore/typing/connection

Conversation

@RA80533

@RA80533 RA80533 commented May 1, 2023

Copy link
Copy Markdown
Contributor

What do these changes do?

  • Converted asyncio.Future-returning methods to native coroutines, updating the return types in the process1
  • Added type annotations to every identifier part of the public API
  • Updated forward ref'd types to use postponed evaluation2

Are there changes in behavior for the user?

Users should now have consistent type hinting when interacting the public API.

Related issue number

#275
#421

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

Footnotes

  1. https://github.com/aio-libs/aioodbc/pull/429#discussion_r1183201672

  2. https://peps.python.org/pep-0563/

@RA80533 RA80533 changed the title Update typing in connection.py Update type annotations in connection.py May 1, 2023
@jettify
jettify marked this pull request as ready for review May 3, 2023 02:56
Comment thread aioodbc/connection.py Outdated
@RA80533
RA80533 requested a review from jettify May 4, 2023 20:52
@jettify

jettify commented May 9, 2023

Copy link
Copy Markdown
Member

Changes looks good but connect kwargs need a fix, mypy not happy.

mypy --ignore-missing-imports aioodbc
[163](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:164)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "str"  [arg-type]
[164](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:165)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "bool"  [arg-type]
[165](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:166)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "int"  [arg-type]
[166](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:167)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[AbstractEventLoop]"  [arg-type]
[167](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:168)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[ThreadPoolExecutor]"  [arg-type]
[168](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:169)
aioodbc/pool.py:161: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[Callable[[Any], Coroutine[Any, Any, Any]]]"  [arg-type]
[169](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:170)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "str"  [arg-type]
[170](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:171)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "bool"  [arg-type]
[171](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:172)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "int"  [arg-type]
[172](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:173)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[AbstractEventLoop]"  [arg-type]
[173](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:174)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[ThreadPoolExecutor]"  [arg-type]
[174](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:175)
aioodbc/pool.py:173: error: Argument 2 to "connect" has incompatible type "**Dict[str, Dict[Any, Any]]"; expected "Optional[Callable[[Any], Coroutine[Any, Any, Any]]]"  [arg-type]
[175](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:176)
Found 12 errors in 1 file (checked 7 source files)
[176](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:177)
make: *** [Makefile:65: mypy] Error 1
[177](https://github.com/aio-libs/aioodbc/actions/runs/4887412629/jobs/8790975578?pr=429#step:5:178)
Error: Process completed with exit code 2.

you can run

make mypy

to repro.

@RA80533
RA80533 force-pushed the chore/typing/connection branch from 9e671b6 to 7e3789f Compare May 10, 2023 20:22
@codecov

codecov Bot commented May 10, 2023

Copy link
Copy Markdown

Codecov Report

Merging #429 (7e3789f) into master (ecc52a6) will increase coverage by 0.08%.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##           master     #429      +/-   ##
==========================================
+ Coverage   86.93%   87.02%   +0.08%     
==========================================
  Files           6        6              
  Lines         490      501      +11     
  Branches       73       73              
==========================================
+ Hits          426      436      +10     
- Misses         48       49       +1     
  Partials       16       16              
Impacted Files Coverage Δ
aioodbc/connection.py 85.62% <93.33%> (+0.40%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@RA80533

RA80533 commented May 10, 2023

Copy link
Copy Markdown
Contributor Author

I rebased the branch with the recent changes. Note the changes in aa8d847; the commit contains the changes associated with the use of asyncio.Future that you recommended.

@skewty

skewty commented Jan 20, 2025

Copy link
Copy Markdown

Any reason this is being held up?

This is ugly:

import aioodbc  # pyright: ignore[reportMissingTypeStubs]

not to mention all the other type issues when using even more strict rule sets such as in basedpyright.

@RA80533

RA80533 commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Does this look like it can be merged, @jettify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants