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

Commite6345d6

Browse files
committed
Replace all Typeguard with cast, revert update to typing-extensions==3.10.0
1 parent0c1446d commite6345d6

File tree

10 files changed

+49
-44
lines changed

10 files changed

+49
-44
lines changed

‎git/config.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
fromtypingimport (Any,Callable,IO,List,Dict,Sequence,
3535
TYPE_CHECKING,Tuple,Union,cast,overload)
3636

37-
fromgit.typesimportLit_config_levels,ConfigLevels_Tup,PathLike,TBD,assert_never,is_config_level
37+
fromgit.typesimportLit_config_levels,ConfigLevels_Tup,PathLike,TBD,assert_never
3838

3939
ifTYPE_CHECKING:
4040
fromgit.repo.baseimportRepo
@@ -309,9 +309,9 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio
309309
else:
310310
ifconfig_levelisNone:
311311
ifread_only:
312-
self._file_or_files= [get_config_path(f)
312+
self._file_or_files= [get_config_path(cast(Lit_config_levels,f))
313313
forfinCONFIG_LEVELS
314-
ifis_config_level(f)andf!='repository']
314+
iff!='repository']
315315
else:
316316
raiseValueError("No configuration level or configuration files specified")
317317
else:

‎git/diff.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
# typing ------------------------------------------------------------------
1717

18-
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING
19-
fromgit.typesimportPathLike,TBD,Literal,TypeGuard
18+
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING,cast
19+
fromgit.typesimportPathLike,TBD,Literal
2020

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
@@ -28,9 +28,9 @@
2828
Lit_change_type=Literal['A','D','C','M','R','T','U']
2929

3030

31-
defis_change_type(inp:str)->TypeGuard[Lit_change_type]:
32-
# return True
33-
returninpin ['A','D','C','M','R','T','U']
31+
#def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
32+
# # return True
33+
# return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
3434

3535
# ------------------------------------------------------------------------
3636

@@ -517,8 +517,8 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
517517
# Change type can be R100
518518
# R: status letter
519519
# 100: score (in case of copy and rename)
520-
assertis_change_type(_change_type[0]),f"Unexpected value for change_type received:{_change_type[0]}"
521-
change_type:Lit_change_type=_change_type[0]
520+
#assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
521+
change_type:Lit_change_type=cast(Lit_change_type,_change_type[0])
522522
score_str=''.join(_change_type[1:])
523523
score=int(score_str)ifscore_str.isdigit()elseNone
524524
path=path.strip()

‎git/index/fun.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
fromtypingimport (Dict,IO,List,Sequence,TYPE_CHECKING,Tuple,Type,Union,cast)
5555

56-
fromgit.typesimportPathLike,TypeGuard
56+
fromgit.typesimportPathLike
5757

5858
ifTYPE_CHECKING:
5959
from .baseimportIndexFile
@@ -188,15 +188,16 @@ def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, i
188188
""":return: Key suitable to be used for the index.entries dictionary
189189
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
190190

191-
defis_entry_key_tup(entry_key:Tuple)->TypeGuard[Tuple[PathLike,int]]:
192-
returnisinstance(entry_key,tuple)andlen(entry_key)==2
191+
#def is_entry_key_tup(entry_key: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
192+
# return isinstance(entry_key, tuple) and len(entry_key) == 2
193193

194194
iflen(entry)==1:
195195
entry_first=entry[0]
196196
assertisinstance(entry_first,BaseIndexEntry)
197197
return (entry_first.path,entry_first.stage)
198198
else:
199-
assertis_entry_key_tup(entry)
199+
# assert is_entry_key_tup(entry)
200+
entry=cast(Tuple[PathLike,int],entry)
200201
returnentry
201202
# END handle entry
202203

@@ -244,7 +245,7 @@ def read_cache(stream: IO[bytes]) -> Tuple[int, Dict[Tuple[PathLike, int], 'Inde
244245
content_sha=extension_data[-20:]
245246

246247
# truncate the sha in the end as we will dynamically create it anyway
247-
extension_data=extension_data[:-20]
248+
extension_data=extension_data[:-20]
248249

249250
return (version,entries,extension_data,content_sha)
250251

‎git/objects/commit.py‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
# typing ------------------------------------------------------------------
4141

42-
fromtypingimportAny,IO,Iterator,List,Sequence,Tuple,Union,TYPE_CHECKING
42+
fromtypingimportAny,IO,Iterator,List,Sequence,Tuple,Union,TYPE_CHECKING,cast
4343

44-
fromgit.typesimportPathLike,TypeGuard,Literal
44+
fromgit.typesimportPathLike,Literal
4545

4646
ifTYPE_CHECKING:
4747
fromgit.repoimportRepo
@@ -323,16 +323,18 @@ def _iter_from_process_or_stream(cls, repo: 'Repo', proc_or_stream: Union[Popen,
323323
:param proc: git-rev-list process instance - one sha per line
324324
:return: iterator returning Commit objects"""
325325

326-
defis_proc(inp)->TypeGuard[Popen]:
327-
returnhasattr(proc_or_stream,'wait')andnothasattr(proc_or_stream,'readline')
326+
#def is_proc(inp) -> TypeGuard[Popen]:
327+
# return hasattr(proc_or_stream, 'wait') and not hasattr(proc_or_stream, 'readline')
328328

329-
defis_stream(inp)->TypeGuard[IO]:
330-
returnhasattr(proc_or_stream,'readline')
329+
#def is_stream(inp) -> TypeGuard[IO]:
330+
# return hasattr(proc_or_stream, 'readline')
331331

332-
ifis_proc(proc_or_stream):
332+
ifhasattr(proc_or_stream,'wait'):
333+
proc_or_stream=cast(Popen,proc_or_stream)
333334
ifproc_or_stream.stdoutisnotNone:
334335
stream=proc_or_stream.stdout
335-
elifis_stream(proc_or_stream):
336+
elifhasattr(proc_or_stream,'readline'):
337+
proc_or_stream=cast(IO,proc_or_stream)
336338
stream=proc_or_stream
337339

338340
readline=stream.readline
@@ -351,7 +353,8 @@ def is_stream(inp) -> TypeGuard[IO]:
351353
# END for each line in stream
352354
# TODO: Review this - it seems process handling got a bit out of control
353355
# due to many developers trying to fix the open file handles issue
354-
ifis_proc(proc_or_stream):
356+
ifhasattr(proc_or_stream,'wait'):
357+
proc_or_stream=cast(Popen,proc_or_stream)
355358
finalize_process(proc_or_stream)
356359

357360
@classmethod

‎git/objects/tree.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
fromtypingimport (Any,Callable,Dict,Iterable,Iterator,List,
2525
Tuple,Type,Union,cast,TYPE_CHECKING)
2626

27-
fromgit.typesimportPathLike,TypeGuard,Literal
27+
fromgit.typesimportPathLike,Literal
2828

2929
ifTYPE_CHECKING:
3030
fromgit.repoimportRepo
@@ -36,8 +36,8 @@
3636
Tuple['Submodule','Submodule']]]
3737

3838

39-
defis_tree_cache(inp:Tuple[bytes,int,str])->TypeGuard[TreeCacheTup]:
40-
returnisinstance(inp[0],bytes)andisinstance(inp[1],int)andisinstance([inp],str)
39+
#def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
40+
# return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
4141

4242
#--------------------------------------------------------
4343

‎git/refs/reference.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# typing ------------------------------------------------------------------
99

1010
fromtypingimportAny,Callable,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING# NOQA
11-
fromgit.typesimportCommit_ish,PathLike,TBD,Literal,TypeGuard,_T# NOQA
11+
fromgit.typesimportCommit_ish,PathLike,TBD,Literal,_T# NOQA
1212

1313
ifTYPE_CHECKING:
1414
fromgit.repoimportRepo

‎git/refs/symbolic.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# typing ------------------------------------------------------------------
2525

2626
fromtypingimportAny,Iterator,List,Match,Optional,Tuple,Type,TypeVar,Union,TYPE_CHECKING# NOQA
27-
fromgit.typesimportCommit_ish,PathLike,TBD,Literal,TypeGuard# NOQA
27+
fromgit.typesimportCommit_ish,PathLike,TBD,Literal# NOQA
2828

2929
ifTYPE_CHECKING:
3030
fromgit.repoimportRepo

‎git/remote.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
# typing-------------------------------------------------------
3838

3939
fromtypingimport (Any,Callable,Dict,Iterator,List,NoReturn,Optional,Sequence,# NOQA[TC002]
40-
TYPE_CHECKING,Type,Union,overload)
40+
TYPE_CHECKING,Type,Union,cast,overload)
4141

42-
fromgit.typesimportPathLike,Literal,TBD,TypeGuard,Commit_ish# NOQA[TC002]
42+
fromgit.typesimportPathLike,Literal,TBD,Commit_ish# NOQA[TC002]
4343

4444
ifTYPE_CHECKING:
4545
fromgit.repo.baseimportRepo
@@ -50,8 +50,8 @@
5050
flagKeyLiteral=Literal[' ','!','+','-','*','=','t','?']
5151

5252

53-
defis_flagKeyLiteral(inp:str)->TypeGuard[flagKeyLiteral]:
54-
returninpin [' ','!','+','-','=','*','t','?']
53+
#def is_flagKeyLiteral(inp: str) -> TypeGuard[flagKeyLiteral]:
54+
# return inp in [' ', '!', '+', '-', '=', '*', 't', '?']
5555

5656

5757
# -------------------------------------------------------------
@@ -342,8 +342,8 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
342342
# parse lines
343343
remote_local_ref_str:str
344344
control_character,operation,local_remote_ref,remote_local_ref_str,note=match.groups()
345-
assertis_flagKeyLiteral(control_character),f"{control_character}"
346-
345+
#assert is_flagKeyLiteral(control_character), f"{control_character}"
346+
control_character=cast(flagKeyLiteral,control_character)
347347
try:
348348
_new_hex_sha,_fetch_operation,fetch_note=fetch_line.split("\t")
349349
ref_type_name,fetch_note=fetch_note.split(' ',1)

‎git/repo/base.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# typing ------------------------------------------------------
3838

39-
fromgit.typesimportTBD,PathLike,Lit_config_levels,Commit_ish,Tree_ish,is_config_level
39+
fromgit.typesimportTBD,PathLike,Lit_config_levels,Commit_ish,Tree_ish
4040
fromtypingimport (Any,BinaryIO,Callable,Dict,
4141
Iterator,List,Mapping,Optional,Sequence,
4242
TextIO,Tuple,Type,Union,
@@ -498,7 +498,8 @@ def config_reader(self, config_level: Optional[Lit_config_levels] = None) -> Git
498498
unknown, instead the global path will be used."""
499499
files=None
500500
ifconfig_levelisNone:
501-
files= [self._get_config_path(f)forfinself.config_levelifis_config_level(f)]
501+
files= [self._get_config_path(cast(Lit_config_levels,f))
502+
forfinself.config_levelifcast(Lit_config_levels,f)]
502503
else:
503504
files= [self._get_config_path(config_level)]
504505
returnGitConfigParser(files,read_only=True,repo=self)

‎git/types.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
else:
1313
fromtyping_extensionsimportFinal,Literal,SupportsIndex,TypedDict,Protocol,runtime_checkable# noqa: F401
1414

15-
ifsys.version_info[:2]>= (3,10):
16-
fromtypingimportTypeGuard# noqa: F401
17-
else:
18-
fromtyping_extensionsimportTypeGuard# noqa: F401
15+
#if sys.version_info[:2] >= (3, 10):
16+
# from typing import TypeGuard # noqa: F401
17+
#else:
18+
# from typing_extensions import TypeGuard # noqa: F401
1919

2020

2121
ifsys.version_info[:2]< (3,9):
@@ -41,9 +41,9 @@
4141
Lit_config_levels=Literal['system','global','user','repository']
4242

4343

44-
defis_config_level(inp:str)->TypeGuard[Lit_config_levels]:
45-
# return inp in get_args(Lit_config_level) # only py >= 3.8
46-
returninpin ("system","user","global","repository")
44+
#def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
45+
# # return inp in get_args(Lit_config_level) # only py >= 3.8
46+
# return inp in ("system", "user", "global", "repository")
4747

4848

4949
ConfigLevels_Tup=Tuple[Literal['system'],Literal['user'],Literal['global'],Literal['repository']]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp