verigak / progress

Easy to use progress bars for Python
ISC License
1.41k stars 179 forks source link

Type hints!!! #90

Open ThatXliner opened 3 years ago

ThatXliner commented 3 years ago

https://kishstats.com/python/2019/01/07/python-type-hinting.html

https://docs.python.org/3/library/typing.html

cclauss commented 3 years ago

$ mypy --install-types --non-interactive .

progress/setup.py:3: error: Skipping analyzing "setuptools": found module but no type hints or library stubs
progress/setup.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
progress/progress/spinner.py:34: error: Incompatible types in assignment (expression has type "List[str]", base class "Spinner" defined the type as "Tuple[str, str, str, str]")
progress/progress/spinner.py:38: error: Incompatible types in assignment (expression has type "List[str]", base class "Spinner" defined the type as "Tuple[str, str, str, str]")
progress/progress/spinner.py:42: error: Incompatible types in assignment (expression has type "List[str]", base class "Spinner" defined the type as "Tuple[str, str, str, str]")
progress/progress/spinner.py:46: error: Incompatible types in assignment (expression has type "List[str]", base class "Spinner" defined the type as "Tuple[str, str, str, str]")
progress/progress/counter.py:48: error: Incompatible types in assignment (expression has type "Tuple[str, str, str, str, str]", base class "Stack" defined the type as "Tuple[str, str, str, str, str, str, str, str, str]")
progress/progress/bar.py:89: error: Incompatible types in assignment (expression has type "Tuple[str, str, str, str, str, str, str, str]", base class "IncrementalBar" defined the type as "Tuple[str, str, str, str, str, str, str, str, str]")
progress/progress/bar.py:93: error: Incompatible types in assignment (expression has type "Tuple[str, str, str, str, str]", base class "IncrementalBar" defined the type as "Tuple[str, str, str, str, str, str, str, str, str]")
Found 8 errors in 4 files (checked 7 source files)
PaulConwayiii commented 2 years ago

I can implement type hints. Will begin work later tonight and send a PR when ready

PaulConwayiii commented 2 years ago

AFAIK there is no way to implement type hints throughout the entire project and still maintain Python 2.6+ compatibility. The issue comes down to having non-literal types (lists, tuples). There is probably a way to make it work, but not cleanly. I also had not realized that when I made my PR that the typing module was introduced in Python 3.5, so that would break compatibility for older Python 3 versions if used. Since Python 2.6+ compatibility is required currently, I say we close this issue until an explicit decision is made by verigak to ditch older Python versions

cclauss commented 2 years ago

Python 2 died 922 days ago on 1/1/2020 so I think it is time to move on... So we can show some progress.

normanr commented 10 months ago

You can also provide type hints in .pyi stub files. Older versions of python just won't read them.

cclauss commented 10 months ago

The project’s name is progress so let’s make some progress by dropping all CPython versions that are no longer supported. Python 2 died 1,465 days ago on 1/1/2020. https://devguide.python.org/versions