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

Python 3 type hints #38

Open
cclauss opened this issue Jun 5, 2021 · 13 comments
Open

Python 3 type hints #38

cclauss opened this issue Jun 5, 2021 · 13 comments
Labels
enhancement Things need to improve or adopt
Milestone

Comments

@cclauss
Copy link
Contributor

cclauss commented Jun 5, 2021

Python type hints would be an interesting direction once Python 2 support is dropped...

$ mypy --ignore-missing-imports .

montydb/montydb/types/_bson.py:279: error: Need type annotation for 'custom_json_hooks' (hint: "custom_json_hooks: Dict[<type>, <type>] = ...")
montydb/montydb/storage/memory.py:14: error: Need type annotation for '_repo'
montydb/montydb/storage/memory.py:15: error: Need type annotation for '_config'
montydb/montydb/storage/memory.py:94: error: Cannot assign to a method
montydb/montydb/storage/memory.py:94: error: Incompatible types in assignment (expression has type "Type[MemoryDatabase]", variable has type "Callable[[AbstractStorage], Any]")
montydb/montydb/storage/memory.py:146: error: Cannot assign to a method
montydb/montydb/storage/memory.py:146: error: Incompatible types in assignment (expression has type "Type[MemoryCollection]", variable has type "Callable[[AbstractDatabase], Any]")
montydb/montydb/storage/memory.py:167: error: Cannot assign to a method
montydb/montydb/storage/memory.py:167: error: Incompatible types in assignment (expression has type "Type[MemoryCursor]", variable has type "Callable[[AbstractCollection], Any]")
montydb/montydb/configure.py:24: error: Need type annotation for '_session' (hint: "_session: Dict[<type>, <type>] = ...")
montydb/montydb/storage/sqlite.py:313: error: Cannot assign to a method
montydb/montydb/storage/sqlite.py:313: error: Incompatible types in assignment (expression has type "Type[SQLiteDatabase]", variable has type "Callable[[AbstractStorage], Any]")
montydb/montydb/storage/sqlite.py:334: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[SQLiteCollection, Any, Any], Any]"; expected "SQLiteCollection"
montydb/montydb/storage/sqlite.py:351: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[SQLiteCollection, Any, Any, Any], Any]"; expected "SQLiteCollection"
montydb/montydb/storage/sqlite.py:414: error: Cannot assign to a method
montydb/montydb/storage/sqlite.py:414: error: Incompatible types in assignment (expression has type "Type[SQLiteCollection]", variable has type "Callable[[AbstractDatabase], Any]")
montydb/montydb/storage/sqlite.py:435: error: Cannot assign to a method
montydb/montydb/storage/sqlite.py:435: error: Incompatible types in assignment (expression has type "Type[SQLiteCursor]", variable has type "Callable[[AbstractCollection], Any]")
montydb/montydb/storage/lightning.py:171: error: Cannot assign to a method
montydb/montydb/storage/lightning.py:171: error: Incompatible types in assignment (expression has type "Type[LMDBDatabase]", variable has type "Callable[[AbstractStorage], Any]")
montydb/montydb/storage/lightning.py:191: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[LMDBCollection, Any, Any, Any], Any]"; expected "LMDBCollection"
montydb/montydb/storage/lightning.py:201: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[LMDBCollection, Any, Any, Any, Any], Any]"; expected "LMDBCollection"
montydb/montydb/storage/lightning.py:241: error: Cannot assign to a method
montydb/montydb/storage/lightning.py:241: error: Incompatible types in assignment (expression has type "Type[LMDBCollection]", variable has type "Callable[[AbstractDatabase], Any]")
montydb/montydb/storage/lightning.py:261: error: Cannot assign to a method
montydb/montydb/storage/lightning.py:261: error: Incompatible types in assignment (expression has type "Type[LMDBCursor]", variable has type "Callable[[AbstractCollection], Any]")
montydb/montydb/storage/flatfile.py:193: error: Cannot assign to a method
montydb/montydb/storage/flatfile.py:193: error: Incompatible types in assignment (expression has type "Type[FlatFileDatabase]", variable has type "Callable[[AbstractStorage], Any]")
montydb/montydb/storage/flatfile.py:220: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[FlatFileCollection, Any, Any], Any]"; expected "FlatFileCollection"
montydb/montydb/storage/flatfile.py:233: error: Argument 1 to "_ensure_table" has incompatible type "Callable[[FlatFileCollection, Any, Any, Any], Any]"; expected "FlatFileCollection"
montydb/montydb/storage/flatfile.py:275: error: Cannot assign to a method
montydb/montydb/storage/flatfile.py:275: error: Incompatible types in assignment (expression has type "Type[FlatFileCollection]", variable has type "Callable[[AbstractDatabase], Any]")
montydb/montydb/storage/flatfile.py:298: error: Cannot assign to a method
montydb/montydb/storage/flatfile.py:298: error: Incompatible types in assignment (expression has type "Type[FlatFileCursor]", variable has type "Callable[[AbstractCollection], Any]")
Found 34 errors in 6 files (checked 100 source files)
@davidlatwe davidlatwe added the enhancement Things need to improve or adopt label Jun 5, 2021
@davidlatwe davidlatwe added this to the 2.4.0 milestone Jun 5, 2021
@davidlatwe
Copy link
Owner

davidlatwe commented Jun 5, 2021

Link this to #27 .
Drop Python 2 support in next minor release.

@davidlatwe
Copy link
Owner

Since #28 is on going, maybe we should start this after #28 is merged so to avoid merging conflicts.
But I am not sure when I am able to back on working #28, hopefully in couple weeks.

@sousajo-cc
Copy link

Can I help on this One?

@davidlatwe
Copy link
Owner

Hi @sousajf1 , sure. :)

I am not sure when I can finish #28 so yeah, we should star this one.

Happy to see improvements!

@madeinoz67
Copy link
Contributor

madeinoz67 commented Jul 7, 2021

seeing you are dropping python 2, I'll remove from dependencies in #57

so supported python versions are 3.7-3.9 ?

@davidlatwe
Copy link
Owner

davidlatwe commented Jul 7, 2021

so supported python versions 3.7-3.9 ?

Should be 3.6-3.9, which are versions being tested in Github Actions.

@madeinoz67
Copy link
Contributor

madeinoz67 commented Jul 7, 2021

so supported python versions 3.7-3.9 ?

Should be 3.6-3.9, which are versions being tested in Github Actions.

hmm I could only see python-version: [ 2.7, 3.7, 3.8, 3.9 ] in your python-package workflow

@davidlatwe
Copy link
Owner

Ouch, I was referencing that info from README ! 🤕
Hmmm, Python 3.6 should be supported, it was in the Azure test before I change to use GitHub Action not long ago.

Could you add it back to the workflow ?

@davidlatwe
Copy link
Owner

Could you add it back to the workflow ?

Hey @madeinoz67 sorry, never mind, just created #59 to see if Python 3.6 still pass the tests.

madeinoz67 added a commit to madeinoz67/montydb that referenced this issue Dec 3, 2021
@bobuk
Copy link
Contributor

bobuk commented May 9, 2022

looks like since v2.4.0 is released there are no deal-breakers to add types hinting?

@davidlatwe
Copy link
Owner

Yeah, that's right! 😄

@cclauss
Copy link
Contributor Author

cclauss commented May 9, 2022

It is easier to add type hints if Python 3.6 is dropped because then from __future__ import annotations can be used to substantially reduce the importing of standard data types (ex. Dict, List, Set, Tuple) from the typing module and to enable the more readable list[str | int | None] syntax. That import is only available on Python >= 3.7. Type hints can still be added on Py3.6 but they will be more verbose.

@davidlatwe
Copy link
Owner

Hi, sorry for bumping this old issue, just wanted to add this note for future self:

We might be able to gain some speed boost with mypyc once we added type hints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Things need to improve or adopt
Projects
None yet
Development

No branches or pull requests

5 participants