diff options
author | Giel van Schijndel <giel@mortis.eu> | 2021-04-23 14:42:03 +0200 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-04-23 21:18:51 +0800 |
commit | 9f12c8c34371a7c46dad6788a48cf092042027ec (patch) | |
tree | b2504dc2341b4f1c7862644835247c48ab600f92 | |
parent | 0767cc527bf3d86c164a6e4f40f39b8f920e05d3 (diff) | |
download | gitpython-9f12c8c34371a7c46dad6788a48cf092042027ec.tar.gz |
fix(types): get the os.PathLike type as correctly as possible
This should make our internal PathLike type compatible with Python <
3.6 and < 3.9.
-rw-r--r-- | git/types.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/git/types.py b/git/types.py index dc44c123..3e33ae0c 100644 --- a/git/types.py +++ b/git/types.py @@ -1,6 +1,20 @@ -import os # @UnusedImport ## not really unused, is in type string +# -*- coding: utf-8 -*- +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +import os +import sys from typing import Union, Any TBD = Any -PathLike = Union[str, 'os.PathLike[str]'] + +if sys.version_info[:2] < (3, 6): + # os.PathLike (PEP-519) only got introduced with Python 3.6 + PathLike = str +elif sys.version_info[:2] < (3, 9): + # Python >= 3.6, < 3.9 + PathLike = Union[str, os.PathLike] +elif sys.version_info[:2] >= (3, 9): + # os.PathLike only becomes subscriptable from Python 3.9 onwards + PathLike = Union[str, os.PathLike[str]] |