pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.42k stars 370 forks source link

Fix `Context.cd()` behavior to match the type hint #922

Open rouge8 opened 1 year ago

rouge8 commented 1 year ago

Issue found when fixing the type hint in typeshed: https://github.com/python/typeshed/pull/9823#pullrequestreview-1316129640

rouge8 commented 1 year ago

Ahh I see, reading the docstring it's the typehint that is wrong. Will fix.

rouge8 commented 1 year ago

Hmm, so the way I see to fix this would be to use a typing.Protocol with a __str__ method, but it looks like invoke supports Python 3.6 which doesn't have that and doesn't currently have a dependency on typing_extensions. Should I add a dependency on typing_extensions to the dev requirements?

JelleZijlstra commented 1 year ago

All objects have __str__ so a protocol for __str__ doesn't make sense. If you only want to support objects that are actually meant to be paths, os.fspath is a better choice.

kuwv commented 1 year ago

I should have checked typeshed. I knew there were types for paramiko but no idea one was created for invoke. I'll see what I can reuse here.

Thanks for the assist!

kuwv commented 1 year ago

956 The os.fspath requires an object to have __fspath__ instead of __str__ for the tests to pass.