8000 Fix Literal Typeguards · gitpython-developers/GitPython@1bcccd5 · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit 1bcccd5

Browse files
committed
Fix Literal Typeguards
1 parent 3578355 commit 1bcccd5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

git/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
31-
return inp in Lit_change_type.__args__ # type: ignore
31+
return inp in ('A', 'D', 'M', 'R', 'T')
3232

3333
# ------------------------------------------------------------------------
3434

git/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
Lit_config_levels = Literal['system', 'global', 'user', 'repository']
3939

4040

41+
def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
42+
return inp in ('system', 'global', 'user', 'repository')
43+
44+
4145
class ConfigLevels_NT(NamedTuple):
4246
"""NamedTuple of allowed CONFIG_LEVELS"""
4347
# works for pylance, but not mypy
@@ -51,10 +55,6 @@ class ConfigLevels_NT(NamedTuple):
5155
# Typing this as specific literals breaks for mypy
5256

5357

54-
def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
55-
return inp in Lit_config_levels.__args__ # type: ignore # mypy lies about __args__
56-
57-
5858
def assert_never(inp: NoReturn, exc: Union[Exception, None] = None) -> NoReturn:
5959
if exc is None:
6060
assert False, f"An unhandled Literal ({inp}) in an if else chain was found"

0 commit comments

Comments
 (0)
0