tox-dev / filelock

A platform-independent file lock for Python.
https://py-filelock.readthedocs.io
The Unlicense
768 stars 107 forks source link

Add type annotations #83

Closed cooperlees closed 3 years ago

cooperlees commented 3 years ago

Would this project be open to adding static type annotations? I ask as firelock is a dependency of mine and failing, naturally.

We can either add the annotations directly to the source code (would require moving to py3 only or using Python 2 comment types - the latter adding tech debt) or we can go the route of adding a .pyi stub file.

Is there any interest in this and if so, which approach would be preferred?

cooperlees commented 3 years ago

O, my bad, there are stubs already. But they seem to be failing for me. Have others got these working with mypy?

crl-m1:bandersnatch cooper$ /tmp/tb/bin/pip install types-filelock
Requirement already satisfied: types-filelock in /private/tmp/tb/lib/python3.9/site-packages (0.1.4)

And I get:

src/bandersnatch_storage_plugins/filesystem.py:12: note: Hint: "python3 -m pip install types-filelock"
src/bandersnatch/mirror.py:17: error: Library stubs not installed for
"filelock" (or incompatible with Python 3.8)

I'd still be open to directly typing the library if people are keen or it.

cooperlees commented 3 years ago

My bad - It was pre-commit virtualenv issues.

Added the following to mypy for other pre-commit peoples:

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.902
    hooks:
      - id: mypy
        exclude: (docs/.*)
        additional_dependencies: ["types-filelock", "types-freezegun", "types-pkg_resources"]
gaborbernat commented 3 years ago

Hello, if you make a PR for this (with tests) we would be happy to review it and accept it, thanks! Note it must be type comments as we still support Python 2 for now.

gaborbernat commented 3 years ago

This is now done.