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

Commit9377462

Browse files
committed
Make has_repo protocol runtime checkable and use in Diffable
1 parent5eea891 commit9377462

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

‎git/config.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def get_config_path(config_level: Lit_config_levels) -> str:
234234
elifconfig_level=="repository":
235235
raiseValueError("No repo to get repository configuration from. Use Repo._get_config_path")
236236
else:
237-
# Should not reach here. Will raise ValueError if does. Static typing will warnabout extra andmissing elifs
238-
assert_never(config_level,ValueError("Invalid configuration level:%r"%config_level))
237+
# Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs
238+
assert_never(config_level,ValueError(f"Invalid configuration level:{config_level!r}"))
239239

240240

241241
classGitConfigParser(with_metaclass(MetaParserBuilder,cp.RawConfigParser,object)):# type: ignore ## mypy does not understand dynamic class creation # noqa: E501

‎git/diff.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# typing ------------------------------------------------------------------
1717

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

2121
ifTYPE_CHECKING:
2222
from .objects.treeimportTree
@@ -141,8 +141,10 @@ def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Inde
141141
ifpathsisnotNoneandnotisinstance(paths, (tuple,list)):
142142
paths= [paths]
143143

144-
ifhasattr(self,'repo'):# else raise Error?
145-
self.repo=self.repo# type: 'Repo'
144+
ifisinstance(self,Has_Repo):
145+
self.repo:Repo=self.repo
146+
else:
147+
raiseAttributeError("No repo member found, cannot create DiffIndex")
146148

147149
diff_cmd=self.repo.git.diff
148150
ifotherisself.Index:

‎git/types.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
importos
66
importsys
7-
fromtypingimport (Callable,Dict,NoReturn,Tuple,Union,Any,Iterator,# noqa: F401
7+
fromtypingimport (Callable,Dict,NoReturn,Sequence,Tuple,Union,Any,Iterator,# noqa: F401
88
NamedTuple,TYPE_CHECKING,TypeVar)# noqa: F401
99

1010
ifTYPE_CHECKING:
@@ -37,6 +37,8 @@
3737
Tree_ish=Union['Commit','Tree']
3838
Commit_ish=Union['Commit','TagObject','Blob','Tree']
3939

40+
# Config_levels ---------------------------------------------------------
41+
4042
Lit_config_levels=Literal['system','global','user','repository']
4143

4244

@@ -47,12 +49,25 @@ def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
4749

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

52+
#-----------------------------------------------------------------------------------
53+
54+
55+
defassert_never(inp:NoReturn,raise_error:bool=True,exc:Union[Exception,None]=None)->None:
56+
"""For use in exhaustive checking of literal or Enum in if/else chain.
57+
Should only be reached if all memebers not handled OR attempt to pass non-members through chain.
58+
59+
If all members handled, type is Empty. Otherwise, will cause mypy error.
60+
If non-members given, should cause mypy error at variable creation.
5061
51-
defassert_never(inp:NoReturn,exc:Union[Exception,None]=None)->NoReturn:
52-
ifexcisNone:
53-
assertFalse,f"An unhandled Literal ({inp}) in an if/else chain was found"
62+
If raise_error is True, will also raise AssertionError or the Exception passed to exc.
63+
"""
64+
ifraise_error:
65+
ifexcisNone:
66+
raiseValueError(f"An unhandled Literal ({inp}) in an if/else chain was found")
67+
else:
68+
raiseexc
5469
else:
55-
raiseexc
70+
pass
5671

5772

5873
classFiles_TD(TypedDict):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp