Skip to content

Commit 13054e8

Browse files
committed
chore: we do a little pre-committing
1 parent 910b401 commit 13054e8

File tree

8 files changed

+25
-36
lines changed

8 files changed

+25
-36
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2020
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21-
DEALINGS IN THE SOFTWARE.
21+
DEALINGS IN THE SOFTWARE.

examples/parser.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import typing
33

44
import velum
5-
import sail
65

6+
import sail
77

88
# Sail implements a bunch of parsers to convert your bot's users' string inputs
99
# to all kinds of types. In most cases, this should be enough to work with to
@@ -34,12 +34,11 @@
3434

3535
import math
3636

37-
from sail.traits import argument_parser_trait
3837
from sail.internal import empty
38+
from sail.traits import argument_parser_trait
3939

4040

4141
class FloatParser(argument_parser_trait.ArgumentParser[float]):
42-
4342
@property
4443
def __type__(self) -> typing.Type[float]:
4544
return float
@@ -70,6 +69,7 @@ def parse(self, argument: str, default: float | empty.Empty = empty.EMPTY) -> fl
7069

7170
# Now we can use this custom parser as part of a command:
7271

72+
7373
@sail.param("number", parser=FloatParser())
7474
@manager.command()
7575
async def cool_floats(ctx: sail.Context, number: float):
@@ -94,22 +94,19 @@ async def cool_floats(ctx: sail.Context, number: float):
9494
# Now, for sake of illustration, we will make a custom container parser for
9595
# lists of strings, that filters out any strings that do not start with "@".
9696

97-
class MentionContainerParser(argument_parser_trait.ContainerParser[typing.List[str]]):
9897

98+
class MentionContainerParser(argument_parser_trait.ContainerParser[typing.List[str]]):
9999
@property
100100
def __type__(self) -> typing.Type[typing.List[str]]:
101101
return typing.List[str]
102102

103103
def parse(
104104
self,
105105
argument: typing.Sequence[object],
106-
default: typing.List[str] | empty.Empty = empty.EMPTY
106+
default: typing.List[str] | empty.Empty = empty.EMPTY,
107107
) -> typing.List[str]:
108108
parsed = [ # fmt: skip
109-
arg
110-
for arg in argument
111-
if isinstance(arg, str)
112-
and arg.startswith("@")
109+
arg for arg in argument if isinstance(arg, str) and arg.startswith("@")
113110
]
114111

115112
if parsed:
@@ -123,6 +120,7 @@ def parse(
123120

124121
# And similarly, this can be passed to a command as follows:
125122

123+
126124
@sail.param("mentions", container_parser=MentionContainerParser())
127125
@manager.command()
128126
async def mention(ctx: sail.Context, mentions: typing.List[str]):

examples/prefix.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import typing
33

44
import velum
5+
56
import sail
67

78
# To create commands, we first create a client as per usual.

examples/turbofish.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import typing
44

55
import velum
6+
67
import sail
78

89
# ...But what if standard prefixes aren't cool enough?

sail/impl/argument_parser.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
import abc
4-
import attr
54
import types
65
import typing
76

7+
import attr
8+
89
from sail import errors
910
from sail.internal import empty
1011
from sail.traits import argument_parser_trait
@@ -136,9 +137,7 @@ def __type__(self) -> typing.Type[ContainerT]:
136137
return self.collection_type
137138

138139
def parse(
139-
self,
140-
argument: typing.Iterable[object],
141-
default: ContainerT | empty.Empty = empty.EMPTY
140+
self, argument: typing.Iterable[object], default: ContainerT | empty.Empty = empty.EMPTY
142141
) -> ContainerT:
143142
try:
144143
return self.collection_type.__call__(argument)
@@ -151,7 +150,6 @@ def parse(
151150

152151
@attr.define()
153152
class SequenceParser(_ContainerParser[SequenceT]):
154-
155153
def __attrs_post_init__(self) -> None:
156154
# In case some non-instantiable generic was passed, default to list.
157155
if isinstance(self.collection_type, abc.ABCMeta):
@@ -160,7 +158,6 @@ def __attrs_post_init__(self) -> None:
160158

161159
@attr.define()
162160
class SetParser(_ContainerParser[SetT]):
163-
164161
def __attrs_post_init__(self) -> None:
165162
# In case some non-instantiable generic was passed, default to set.
166163
if isinstance(self.collection_type, abc.ABCMeta):
@@ -178,29 +175,26 @@ def __type__(self) -> typing.Type[None]:
178175
return types.NoneType
179176

180177
def parse(
181-
self,
182-
argument: typing.Sequence[object],
183-
default: typing.Any | empty.Empty = empty.EMPTY
178+
self, argument: typing.Sequence[object], default: typing.Any | empty.Empty = empty.EMPTY
184179
) -> typing.Any:
185180
if len(argument) == 1:
186181
return argument[0]
187-
182+
188183
elif len(argument) > 1:
189184
raise errors.ConversionError(
190185
argument,
191186
self.__type__,
192-
TypeError("Got more than 1 argument for a parameter without a container type.")
187+
TypeError("Got more than 1 argument for a parameter without a container type."),
193188
)
194-
189+
195190
elif empty.is_nonempty(default):
196191
return default
197192

198193
raise errors.ConversionError(
199-
argument,
200-
self.__type__,
201-
TypeError("Got 0 arguments for required parameter.")
194+
argument, self.__type__, TypeError("Got 0 arguments for required parameter.")
202195
) from None
203196

197+
204198
@attr.define()
205199
class JoinedStringParser(argument_parser_trait.ContainerParser[str]):
206200

@@ -211,16 +205,14 @@ def __type__(self) -> typing.Type[str]:
211205
return str
212206

213207
def parse(
214-
self,
215-
argument: typing.Sequence[object],
216-
default: str | empty.Empty = empty.EMPTY
208+
self, argument: typing.Sequence[object], default: str | empty.Empty = empty.EMPTY
217209
) -> str:
218210
if not argument:
219211
if empty.is_nonempty(default):
220212
return default
221213

222214
raise TypeError("Got 0 arguments for required parameter.")
223-
215+
224216
assert all(isinstance(arg, str) for arg in argument)
225217

226218
return self.separator.join(typing.cast(typing.Sequence[str], argument))

sail/impl/command.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ def param(
153153
name: str,
154154
/,
155155
*,
156-
parser: undefined.UndefinedOr[
157-
argument_parser_trait.ArgumentParser[T]
158-
] = undefined.UNDEFINED,
156+
parser: undefined.UndefinedOr[argument_parser_trait.ArgumentParser[T]] = undefined.UNDEFINED,
159157
container_parser: undefined.UndefinedOr[
160158
argument_parser_trait.ContainerParser[typing.Any]
161159
] = undefined.UNDEFINED,
@@ -164,7 +162,6 @@ def param(
164162
greedy: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
165163
flag: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
166164
) -> typing.Callable[[CommandT], CommandT]:
167-
168165
def wrapper(command: CommandT) -> CommandT:
169166
command.update_param_typesafe(
170167
name,
@@ -177,5 +174,5 @@ def wrapper(command: CommandT) -> CommandT:
177174
)
178175

179176
return command
180-
177+
181178
return wrapper

sail/internal/debug.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def test_invoke(manager: command_manager.CommandManager, invocation: str)
1919
await manager.try_invoke(debug_event)
2020

2121
except Exception as exc:
22-
exc_info = type(exc), exc, exc.__traceback__ #.tb_next if exc.__traceback__ else None
22+
exc_info = type(exc), exc, exc.__traceback__ # .tb_next if exc.__traceback__ else None
2323

2424
_LOGGER.error(
2525
"Test invocation failed.",

sail/traits/argument_parser_trait.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ def __type__(self) -> typing.Type[ContainerT]:
3030
def parse(
3131
self,
3232
argument: typing.Sequence[object],
33-
default: ContainerT | empty.Empty = empty.EMPTY
33+
default: ContainerT | empty.Empty = empty.EMPTY,
3434
) -> ContainerT:
3535
...

0 commit comments

Comments
 (0)