Skip to content

Use Python type annotations #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cool-RR opened this issue Feb 24, 2017 · 4 comments
Closed

Use Python type annotations #591

cool-RR opened this issue Feb 24, 2017 · 4 comments

Comments

@cool-RR
Copy link
Contributor

cool-RR commented Feb 24, 2017

I use an IDE to work with GitPython, and if you'd used type annotations on your methods, it'll be able to give me autocompletion when working with GitPython. For example:

def clone(self, path, progress=None, **kwargs) -> 'Repo':
    # ...

(The quotes are needed here because the class isn't defined yet when the method is being defined, in other cases you may use the class directly.)

@sethmlarson
Copy link

sethmlarson commented Feb 24, 2017

This horribly breaks all Python 3.5< so I think this is a bad idea. Maybe would be better to use mypy annotations, or perhaps even docstring type annotations? I know that PyCharm picks those up.

For example I'm talking something like this:

def clone(self, path, progress=None, **kwargs):
    """
    :param str path:
    :rtype: Repo
    """
    # Define clone down here

@cool-RR
Copy link
Contributor Author

cool-RR commented Feb 24, 2017

I believe you're wrong. Python annotation syntax goes back to 3.0, so it's available on all Python 3 versions.

https://www.python.org/dev/peps/pep-3107/

@Byron Byron added the rejected label Feb 25, 2017
@Byron
Copy link
Member

Byron commented Feb 25, 2017

GitPython must support python 2.7, which makes this kind of syntax a breaking change.
In case there are other syntaxes that are compatible with all python versions GitPython has to support, please feel free to provide an exhaustive PR to declare each and every type.

@Byron Byron closed this as completed Feb 25, 2017
@jlisee
Copy link

jlisee commented Feb 18, 2020

Since this library supports only Python 3.4+ now, @Byron would you be willing to re-open the issue?

I come at this from a speed and correctness of development angle. It's hard to get interactions with a git repository correct, and difficult to test things like CI/CD or build system they are usually involved in. So having the ability for a type checker to find a lot of failure cases for you would be a big help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants