tomerfiliba / plumbum

Plumbum: Shell Combinators
https://plumbum.readthedocs.io
MIT License
2.79k stars 182 forks source link

Type hints for library #334

Open asmfreak opened 7 years ago

asmfreak commented 7 years ago

Please add type hints for your awesome library, so it can use with mypy checking. Here is some info on how to do this mainly painlessly

henryiii commented 7 years ago

Could you suggest places to add them to expedite the process? I'm familiar with them, and love to see that people are beginning to use them. I'll take PRs (Especially easy for type hints, since they are simply new stub files). I use PyCharm, which also would benefit from type hints.

asmfreak commented 7 years ago

mypy complains about functions wrapped with plumbum.cli.Predicate: error: Invalid type "..." Shoul I open another issue for this? An example:

from plumbum import cli
@cli.Predicate
def GummyBear(n):
    if not n.startswith('gummybear'):
        raise ValueError('{} is not a gummybear!'.format(n))
    return n

class GummyConsumer(cli.Application):
    def main(self, bear: GummyBear):
        print('MUNCH MUNCH MUNCH')
$ mypy gummy.py
gummy.py:1: error: Cannot find module named 'plumbum'
gummy.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
gummy.py:9: error: Invalid type "gummy.GummyBear"
henryiii commented 7 years ago

Yes, that needs its own issue, it's caused by Plumbum optionally using type hints as part of the API, and that needs to be made compatible with mypy.

mdantonio commented 3 years ago

Hello, this issue is open since a lot of time... can I ask if there are updates on type hints for plumbum? I think that types would be very useful. Thank you a lot!

henryiii commented 3 years ago

Happy to take a PR. Currently we still keep compatibility with Python 2 making it a little harder. I was planning to drop Python 2 Jan 1, 2022 unless @tomerfiliba needs it for some reason. Old plumbum will still work on Python 2 past that point, it just won't get any more updates. Tempted to just drop that much sooner, as the next two features that I don't have time to work on are pulling out at least plumbum.colorlib and plumbum.cli into separate packages, and that's easier in Python 3, and after that adding async support, also easier in Python 3.

kierun commented 2 years ago

Any updates now that Jan 1, 2022 is past?

I am happy to test things but sadly, do not have time to contribute. :(

jacobjove commented 10 months ago
Screenshot 2023-10-11 at 8 32 06 PM

Cool library! Bummer there are no types.