Skip to content

Drop 3.6, increase type strictness #1311

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

Merged
merged 36 commits into from
Aug 3, 2021
Merged
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
39d37d5
replace some TBDs wiht runtime types
Yobmod Jul 31, 2021
c878771
replace more TBDs wiht runtime types
Yobmod Jul 31, 2021
009017e
Merge branch 'gitpython-developers:main' into main
Yobmod Aug 2, 2021
2163322
increase mypy strictness (warn unused ignored)
Yobmod Aug 2, 2021
0525c17
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Aug 2, 2021
91fce33
increase mypy strictness (warn unused ignored and warn unreachable)
Yobmod Aug 2, 2021
15ace87
rmv 3.6 from CI matrix
Yobmod Aug 2, 2021
bef2182
rmv 3.6 from setup.py
Yobmod Aug 2, 2021
270c3d7
rmv 3.6 README
Yobmod Aug 2, 2021
c3f3501
Add __future__.annotations to cmd.py
Yobmod Aug 2, 2021
829142d
Add __future__.annotations to cmd.py2
Yobmod Aug 2, 2021
13e0730
Fix parse_date typing
Yobmod Aug 2, 2021
730f119
Fix parse_date typing 2
Yobmod Aug 2, 2021
2fe13ca
Fix parse_date typing 3
Yobmod Aug 2, 2021
024b696
Fix parse_date typing 4
Yobmod Aug 2, 2021
e2f8367
Fix parse_date typing 5
Yobmod Aug 2, 2021
d30bc07
Fix parse_date typing 6
Yobmod Aug 2, 2021
6470ad4
Fix parse_date typing 7
Yobmod Aug 2, 2021
481f672
Add __future__.annotations to repo/base.py
Yobmod Aug 2, 2021
9de7310
Minor type fixes
Yobmod Aug 2, 2021
5647d58
Merge branch 'gitpython-developers:main' into main
Yobmod Aug 2, 2021
f34a39f
Test new union syntax (Pep604)
Yobmod Aug 2, 2021
3b53d28
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Aug 2, 2021
4dd06c3
Test trailing comma in args (>py3.6?)
Yobmod Aug 2, 2021
94ae0c5
Test Dataclass in repo.base.blame()
Yobmod Aug 2, 2021
a3f5b13
Test Dataclass in repo.base.blame() 2
Yobmod Aug 2, 2021
a2a36e0
Test Dataclass in repo.base.blame() 3
Yobmod Aug 2, 2021
ed137cb
Test TypedDict in repo.base.blame() 2
Yobmod Aug 2, 2021
e4761ff
Test TypedDict in repo.base.blame() 1
Yobmod Aug 2, 2021
1aaa704
Test Dataclass in repo.base.blame() 4
Yobmod Aug 2, 2021
bc9bcf5
Test Dataclass in repo.base.blame() 5
Yobmod Aug 2, 2021
ad417ba
Test Dataclass in repo.base.blame() 6
Yobmod Aug 2, 2021
ecb1f79
Choose TypedDict!
Yobmod Aug 2, 2021
5aa8c34
Improve type of repo.blame_incremental()
Yobmod Aug 2, 2021
8b8aa16
Improve type of repo.currently_rebasing_on()
Yobmod Aug 2, 2021
84232f7
Add Typing :: Typed to setup.py
Yobmod Aug 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10.0-beta.4"]
python-version: [3.7, 3.8, 3.9, "3.10.0-beta.4"]

steps:
- uses: actions/checkout@v2
87 changes: 42 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,32 +24,30 @@ or low-level like git-plumbing.

It provides abstractions of git objects for easy access of repository data, and additionally
allows you to access the git repository more directly using either a pure python implementation,
or the faster, but more resource intensive *git command* implementation.
or the faster, but more resource intensive _git command_ implementation.

The object database implementation is optimized for handling large quantities of objects and large datasets,
which is achieved by using low-level structures and data streaming.


### DEVELOPMENT STATUS

This project is in **maintenance mode**, which means that

* …there will be no feature development, unless these are contributed
* …there will be no bug fixes, unless they are relevant to the safety of users, or contributed
* …issues will be responded to with waiting times of up to a month
- …there will be no feature development, unless these are contributed
- …there will be no bug fixes, unless they are relevant to the safety of users, or contributed
- …issues will be responded to with waiting times of up to a month

The project is open to contributions of all kinds, as well as new maintainers.


### REQUIREMENTS

GitPython needs the `git` executable to be installed on the system and available
in your `PATH` for most operations.
If it is not in your `PATH`, you can help GitPython find it by setting
the `GIT_PYTHON_GIT_EXECUTABLE=<path/to/git>` environment variable.

* Git (1.7.x or newer)
* Python >= 3.6
- Git (1.7.x or newer)
- Python >= 3.7

The list of dependencies are listed in `./requirements.txt` and `./test-requirements.txt`.
The installer takes care of installing them for you.
@@ -98,57 +96,56 @@ See [Issue #525](https://github.com/gitpython-developers/GitPython/issues/525).

### RUNNING TESTS

*Important*: Right after cloning this repository, please be sure to have executed
_Important_: Right after cloning this repository, please be sure to have executed
the `./init-tests-after-clone.sh` script in the repository root. Otherwise
you will encounter test failures.

On *Windows*, make sure you have `git-daemon` in your PATH. For MINGW-git, the `git-daemon.exe`
On _Windows_, make sure you have `git-daemon` in your PATH. For MINGW-git, the `git-daemon.exe`
exists in `Git\mingw64\libexec\git-core\`; CYGWIN has no daemon, but should get along fine
with MINGW's.

Ensure testing libraries are installed.
In the root directory, run: `pip install -r test-requirements.txt`
Ensure testing libraries are installed.
In the root directory, run: `pip install -r test-requirements.txt`

To lint, run: `flake8`

To typecheck, run: `mypy -p git`
To typecheck, run: `mypy -p git`

To test, run: `pytest`

Configuration for flake8 is in the ./.flake8 file.

Configurations for mypy, pytest and coverage.py are in ./pyproject.toml.

The same linting and testing will also be performed against different supported python versions
The same linting and testing will also be performed against different supported python versions
upon submitting a pull request (or on each push if you have a fork with a "main" branch and actions enabled).


### Contributions

Please have a look at the [contributions file][contributing].

### INFRASTRUCTURE

* [User Documentation](http://gitpython.readthedocs.org)
* [Questions and Answers](http://stackexchange.com/filters/167317/gitpython)
* Please post on stackoverflow and use the `gitpython` tag
* [Issue Tracker](https://github.com/gitpython-developers/GitPython/issues)
* Post reproducible bugs and feature requests as a new issue.
- [User Documentation](http://gitpython.readthedocs.org)
- [Questions and Answers](http://stackexchange.com/filters/167317/gitpython)
- Please post on stackoverflow and use the `gitpython` tag
- [Issue Tracker](https://github.com/gitpython-developers/GitPython/issues)
- Post reproducible bugs and feature requests as a new issue.
Please be sure to provide the following information if posting bugs:
* GitPython version (e.g. `import git; git.__version__`)
* Python version (e.g. `python --version`)
* The encountered stack-trace, if applicable
* Enough information to allow reproducing the issue
- GitPython version (e.g. `import git; git.__version__`)
- Python version (e.g. `python --version`)
- The encountered stack-trace, if applicable
- Enough information to allow reproducing the issue

### How to make a new release

* Update/verify the **version** in the `VERSION` file
* Update/verify that the `doc/source/changes.rst` changelog file was updated
* Commit everything
* Run `git tag -s <version>` to tag the version in Git
* Run `make release`
* Close the milestone mentioned in the _changelog_ and create a new one. _Do not reuse milestones by renaming them_.
* set the upcoming version in the `VERSION` file, usually be
- Update/verify the **version** in the `VERSION` file
- Update/verify that the `doc/source/changes.rst` changelog file was updated
- Commit everything
- Run `git tag -s <version>` to tag the version in Git
- Run `make release`
- Close the milestone mentioned in the _changelog_ and create a new one. _Do not reuse milestones by renaming them_.
- set the upcoming version in the `VERSION` file, usually be
incrementing the patch level, and possibly by appending `-dev`. Probably you
want to `git push` once more.

@@ -200,22 +197,22 @@ gpg --edit-key 4C08421980C9

### Projects using GitPython

* [PyDriller](https://github.com/ishepard/pydriller)
* [Kivy Designer](https://github.com/kivy/kivy-designer)
* [Prowl](https://github.com/nettitude/Prowl)
* [Python Taint](https://github.com/python-security/pyt)
* [Buster](https://github.com/axitkhurana/buster)
* [git-ftp](https://github.com/ezyang/git-ftp)
* [Git-Pandas](https://github.com/wdm0006/git-pandas)
* [PyGitUp](https://github.com/msiemens/PyGitUp)
* [PyJFuzz](https://github.com/mseclab/PyJFuzz)
* [Loki](https://github.com/Neo23x0/Loki)
* [Omniwallet](https://github.com/OmniLayer/omniwallet)
* [GitViper](https://github.com/BeayemX/GitViper)
* [Git Gud](https://github.com/bthayer2365/git-gud)
- [PyDriller](https://github.com/ishepard/pydriller)
- [Kivy Designer](https://github.com/kivy/kivy-designer)
- [Prowl](https://github.com/nettitude/Prowl)
- [Python Taint](https://github.com/python-security/pyt)
- [Buster](https://github.com/axitkhurana/buster)
- [git-ftp](https://github.com/ezyang/git-ftp)
- [Git-Pandas](https://github.com/wdm0006/git-pandas)
- [PyGitUp](https://github.com/msiemens/PyGitUp)
- [PyJFuzz](https://github.com/mseclab/PyJFuzz)
- [Loki](https://github.com/Neo23x0/Loki)
- [Omniwallet](https://github.com/OmniLayer/omniwallet)
- [GitViper](https://github.com/BeayemX/GitViper)
- [Git Gud](https://github.com/bthayer2365/git-gud)

### LICENSE

New BSD License. See the LICENSE file.
New BSD License. See the LICENSE file.

[contributing]: https://github.com/gitpython-developers/GitPython/blob/master/CONTRIBUTING.md
6 changes: 4 additions & 2 deletions doc/source/intro.rst
Original file line number Diff line number Diff line change
@@ -13,15 +13,17 @@ The object database implementation is optimized for handling large quantities of
Requirements
============

* `Python`_ >= 3.6
* `Python`_ >= 3.7
* `Git`_ 1.7.0 or newer
It should also work with older versions, but it may be that some operations
involving remotes will not work as expected.
* `GitDB`_ - a pure python git database implementation
* `typing_extensions`_ >= 3.10.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to requirements.txt this should be "typing-extensions>=3.7.4.3;python_version<"3.10""


.. _Python: https://www.python.org
.. _Git: https://git-scm.com/
.. _GitDB: https://pypi.python.org/pypi/gitdb
.. _typing_extensions: https://pypi.org/project/typing-extensions/

Installing GitPython
====================
@@ -60,7 +62,7 @@ Leakage of System Resources
---------------------------

GitPython is not suited for long-running processes (like daemons) as it tends to
leak system resources. It was written in a time where destructors (as implemented
leak system resources. It was written in a time where destructors (as implemented
in the `__del__` method) still ran deterministically.

In case you still want to use it in such a context, you will want to search the
37 changes: 17 additions & 20 deletions git/cmd.py
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
from typing import (Any, AnyStr, BinaryIO, Callable, Dict, IO, Iterator, List, Mapping,
Sequence, TYPE_CHECKING, TextIO, Tuple, Union, cast, overload)

from git.types import PathLike, Literal
from git.types import PathLike, Literal, TBD

if TYPE_CHECKING:
from git.repo.base import Repo
@@ -68,7 +68,7 @@
# Documentation
## @{

def handle_process_output(process: subprocess.Popen,
def handle_process_output(process: Union[subprocess.Popen, 'Git.AutoInterrupt'],
stdout_handler: Union[None,
Callable[[AnyStr], None],
Callable[[List[AnyStr]], None],
@@ -77,7 +77,7 @@ def handle_process_output(process: subprocess.Popen,
Callable[[AnyStr], None],
Callable[[List[AnyStr]], None]],
finalizer: Union[None,
Callable[[subprocess.Popen], None]] = None,
Callable[[Union[subprocess.Popen, 'Git.AutoInterrupt']], None]] = None,
decode_streams: bool = True) -> None:
"""Registers for notifications to learn that process output is ready to read, and dispatches lines to
the respective line handlers.
@@ -165,7 +165,7 @@ def dict_to_slots_and__excluded_are_none(self: object, d: Mapping[str, Any], exc
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
# see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP # type: ignore[attr-defined]
if is_win else 0)
if is_win else 0) # mypy error if not windows


class Git(LazyMixin):
@@ -421,27 +421,27 @@ def __getattr__(self, attr: str) -> Any:
return getattr(self.proc, attr)

# TODO: Bad choice to mimic `proc.wait()` but with different args.
def wait(self, stderr: Union[None, bytes] = b'') -> int:
def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
"""Wait for the process and return its status code.

:param stderr: Previously read value of stderr, in case stderr is already closed.
:warn: may deadlock if output or error pipes are used and not handled separately.
:raise GitCommandError: if the return status is not 0"""
if stderr is None:
stderr = b''
stderr = force_bytes(data=stderr, encoding='utf-8')
stderr_b = b''
stderr_b = force_bytes(data=stderr, encoding='utf-8')

if self.proc is not None:
status = self.proc.wait()

def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> bytes:
if stream:
try:
return stderr + force_bytes(stream.read())
return stderr_b + force_bytes(stream.read())
except ValueError:
return stderr or b''
return stderr_b or b''
else:
return stderr or b''
return stderr_b or b''

if status != 0:
errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
@@ -575,8 +575,8 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
self._environment: Dict[str, str] = {}

# cached command slots
self.cat_file_header = None
self.cat_file_all = None
self.cat_file_header: Union[None, TBD] = None
self.cat_file_all: Union[None, TBD] = None

def __getattr__(self, name: str) -> Any:
"""A convenience method as it allows to call the command as if it was
@@ -1012,17 +1012,14 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any

@classmethod
def __unpack_args(cls, arg_list: Sequence[str]) -> List[str]:
if not isinstance(arg_list, (list, tuple)):
return [str(arg_list)]

outlist = []
for arg in arg_list:
if isinstance(arg_list, (list, tuple)):
if isinstance(arg_list, (list, tuple)):
for arg in arg_list:
outlist.extend(cls.__unpack_args(arg))
# END recursion
else:
outlist.append(str(arg))
# END for each arg
else:
outlist.append(str(arg_list))

return outlist

def __call__(self, **kwargs: Any) -> 'Git':
18 changes: 0 additions & 18 deletions git/compat.py
Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@
Union,
overload,
)
from git.types import TBD

# ---------------------------------------------------------------------------


@@ -97,19 +95,3 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
elif s is not None:
raise TypeError('Expected bytes or text, but got %r' % (s,))
return None


# type: ignore ## mypy cannot understand dynamic class creation
def with_metaclass(meta: Type[Any], *bases: Any) -> TBD:
"""copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""

class metaclass(meta): # type: ignore
__call__ = type.__call__
__init__ = type.__init__ # type: ignore

def __new__(cls, name: str, nbases: Optional[Tuple[int, ...]], d: Dict[str, Any]) -> TBD:
if nbases is None:
return type.__new__(cls, name, (), d)
return meta(name, bases, d)

return metaclass(meta.__name__ + 'Helper', None, {}) # type: ignore
Loading