Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5778b7a

Browse files
committed
Use LBYL for imports where EAFP is a mypy type error
The conditional imports of Literal from either typing ortyping_extensions have to be done with if-else on the Pythonversion rather than with try-except, or it is a static type error.This makes that change, checking sys.version_info.(See discussion in#1861 and#1862 for broader context andbackground on why this logic, before and after this change, isrepeated across multiple modules.)This also reorders/regroups imports for consistency in some places,especially where a new import of the sys module (for version_info)would otherwise exacerbate inconsistency.Since the merge commit0b99041, the number of mypy errors hadincreased from 5 to 10. This fixes all the new mypy errors, so thecount is back to 5.
1 parent74f3c2e commit5778b7a

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

‎git/objects/blob.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

66
frommimetypesimportguess_type
7-
from .importbase
7+
importsys
88

9+
from .importbase
910

10-
try:
11+
ifsys.version_info>= (3,8):
1112
fromtypingimportLiteral
12-
exceptImportError:
13+
else:
1314
fromtyping_extensionsimportLiteral
1415

1516
__all__= ("Blob",)

‎git/objects/commit.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,57 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6+
fromcollectionsimportdefaultdict
67
importdatetime
8+
fromioimportBytesIO
9+
importlogging
10+
importos
711
importre
812
fromsubprocessimportPopen,PIPE
13+
importsys
14+
fromtimeimportaltzone,daylight,localtime,time,timezone
15+
916
fromgitdbimportIStream
10-
fromgit.utilimporthex_to_bin,Actor,Stats,finalize_process
11-
fromgit.diffimportDiffable
1217
fromgit.cmdimportGit
18+
fromgit.diffimportDiffable
19+
fromgit.utilimporthex_to_bin,Actor,Stats,finalize_process
1320

1421
from .treeimportTree
15-
from .importbase
1622
from .utilimport (
1723
Serializable,
1824
TraversableIterableObj,
19-
parse_date,
2025
altz_to_utctz_str,
21-
parse_actor_and_date,
2226
from_timestamp,
27+
parse_actor_and_date,
28+
parse_date,
2329
)
24-
25-
fromtimeimporttime,daylight,altzone,timezone,localtime
26-
importos
27-
fromioimportBytesIO
28-
importlogging
29-
fromcollectionsimportdefaultdict
30-
30+
from .importbase
3131

3232
# typing ------------------------------------------------------------------
3333

3434
fromtypingimport (
3535
Any,
36+
Dict,
3637
IO,
3738
Iterator,
3839
List,
3940
Sequence,
4041
Tuple,
41-
Union,
4242
TYPE_CHECKING,
43+
Union,
4344
cast,
44-
Dict,
4545
)
4646

47-
fromgit.typesimportPathLike
48-
49-
try:
47+
ifsys.version_info>= (3,8):
5048
fromtypingimportLiteral
51-
exceptImportError:
49+
else:
5250
fromtyping_extensionsimportLiteral
5351

52+
fromgit.typesimportPathLike
53+
5454
ifTYPE_CHECKING:
55-
fromgit.repoimportRepo
5655
fromgit.refsimportSymbolicReference
56+
fromgit.repoimportRepo
5757

5858
# ------------------------------------------------------------------------
5959

‎git/objects/submodule/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
sm_section,
4040
)
4141

42-
4342
# typing ----------------------------------------------------------------------
4443

4544
fromtypingimport (
@@ -54,13 +53,13 @@
5453
cast,
5554
)
5655

57-
fromgit.typesimportCommit_ish,PathLike,TBD
58-
59-
try:
56+
ifsys.version_info>= (3,8):
6057
fromtypingimportLiteral
61-
exceptImportError:
58+
else:
6259
fromtyping_extensionsimportLiteral
6360

61+
fromgit.typesimportCommit_ish,PathLike,TBD
62+
6463
ifTYPE_CHECKING:
6564
fromgit.indeximportIndexFile
6665
fromgit.objects.commitimportCommit

‎git/objects/tag.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
For lightweight tags, see the :mod:`git.refs.tag` module.
1010
"""
1111

12+
importsys
13+
1214
from .importbase
1315
from .utilimportget_object_type_by_name,parse_actor_and_date
1416
from ..utilimporthex_to_bin
1517
from ..compatimportdefenc
1618

1719
fromtypingimportList,TYPE_CHECKING,Union
1820

19-
try:
21+
ifsys.version_info>= (3,8):
2022
fromtypingimportLiteral
21-
exceptImportError:
23+
else:
2224
fromtyping_extensionsimportLiteral
2325

2426
ifTYPE_CHECKING:

‎git/objects/tree.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6-
fromgit.utilimportIterableList,join_path
6+
importsys
7+
78
importgit.diffasgit_diff
8-
fromgit.utilimportto_bin_sha
9+
fromgit.utilimportIterableList,join_path,to_bin_sha
910

10-
from .importutil
11-
from .baseimportIndexObject,IndexObjUnion
11+
from .baseimportIndexObjUnion,IndexObject
1212
from .blobimportBlob
13-
from .submodule.baseimportSubmodule
14-
1513
from .funimporttree_entries_from_data,tree_to_stream
16-
14+
from .submodule.baseimportSubmodule
15+
from .importutil
1716

1817
# typing -------------------------------------------------
1918

@@ -25,22 +24,22 @@
2524
Iterator,
2625
List,
2726
Tuple,
27+
TYPE_CHECKING,
2828
Type,
2929
Union,
3030
cast,
31-
TYPE_CHECKING,
3231
)
3332

34-
fromgit.typesimportPathLike
35-
36-
try:
33+
ifsys.version_info>= (3,8):
3734
fromtypingimportLiteral
38-
exceptImportError:
35+
else:
3936
fromtyping_extensionsimportLiteral
4037

38+
fromgit.typesimportPathLike
39+
4140
ifTYPE_CHECKING:
42-
fromgit.repoimportRepo
4341
fromioimportBytesIO
42+
fromgit.repoimportRepo
4443

4544
TreeCacheTup=Tuple[bytes,int,str]
4645

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp