davidlatwe / montydb

Monty, Mongo tinified. MongoDB implemented in Python !

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python 3 type hints

cclauss opened this issue · comments

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)

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

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.

Can I help on this One?

Hi @sousajf1 , sure. :)

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

Happy to see improvements!

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

so supported python versions are 3.7-3.9 ?

so supported python versions 3.7-3.9 ?

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

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

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 ?

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.

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

Yeah, that's right! 😄

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.