Skip to content

Commit 9f12c8c

Browse files
muggenhorByron
authored andcommitted
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.
1 parent 0767cc5 commit 9f12c8c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

git/types.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
import os # @UnusedImport ## not really unused, is in type string
1+
# -*- coding: utf-8 -*-
2+
# This module is part of GitPython and is released under
3+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
4+
5+
import os
6+
import sys
27
from typing import Union, Any
38

49

510
TBD = Any
6-
PathLike = Union[str, 'os.PathLike[str]']
11+
12+
if sys.version_info[:2] < (3, 6):
13+
# os.PathLike (PEP-519) only got introduced with Python 3.6
14+
PathLike = str
15+
elif sys.version_info[:2] < (3, 9):
16+
# Python >= 3.6, < 3.9
17+
PathLike = Union[str, os.PathLike]
18+
elif sys.version_info[:2] >= (3, 9):
19+
# os.PathLike only becomes subscriptable from Python 3.9 onwards
20+
PathLike = Union[str, os.PathLike[str]]

0 commit comments

Comments
 (0)