Skip to content

Commit 08d8a8d

Browse files
authored
Merge pull request #100 from yassun7010/use_assert_never
chore: use assert_never.
2 parents f80cf51 + c37a730 commit 08d8a8d

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

cmdcomp/completion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import assert_never
2+
13
from cmdcomp.config import Config
2-
from cmdcomp.exception import NeverReach
34
from cmdcomp.shell import ShellType
45
from cmdcomp.v1.completion import generate_v1
56
from cmdcomp.v1.config import V1Config
@@ -16,4 +17,4 @@ def generate(shell: ShellType, config: Config) -> str:
1617
return generate_v2(shell, config.root)
1718

1819
case _:
19-
raise NeverReach(config.root)
20+
assert_never(config.root)

cmdcomp/exception.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from typing import Never
2-
3-
41
class CmdcompError(Exception):
52
pass
63

@@ -12,11 +9,3 @@ def __init__(self, file: str, extension: str) -> None:
129

1310
def __str__(self) -> str:
1411
return f'file extension "{self._extension}" of "{self._file}" is not supported.'
15-
16-
17-
class NeverReach(CmdcompError):
18-
def __init__(self, value: Never) -> None:
19-
self._value = value
20-
21-
def __str__(self) -> str:
22-
return f"never reach: {self._value}"

cmdcomp/v1/command/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from functools import reduce
22
from operator import add
3-
from typing import Annotated, NewType, OrderedDict
3+
from typing import Annotated, NewType, OrderedDict, assert_never
44

55
from pydantic import ConfigDict, Field
66

7-
from cmdcomp.exception import NeverReach
87
from cmdcomp.model import Model
98
from cmdcomp.v1.command.option import V1OptionType, V1SpecificOptions, V1StrOption
109
from cmdcomp.v1.command.option.command_option import V1CommandOption
@@ -89,6 +88,6 @@ def get_candidates(command: V1Command) -> V1Candidates:
8988
elif isinstance(command.options, V1FileOption):
9089
return [{"file": command.options.base_path}]
9190
else:
92-
raise NeverReach(command.options)
91+
assert_never(command.options)
9392
case _:
94-
raise NeverReach(command)
93+
assert_never(command)

0 commit comments

Comments
 (0)