Skip to content

Commit 3faabc4

Browse files
committed
Rename parameter check to filter
1 parent 24b1cf4 commit 3faabc4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ These changes are available on the `master` branch, but have not yet been releas
2222
`tags`. ([#2520](https://github.com/Pycord-Development/pycord/pull/2520))
2323
- Added `Member.guild_banner` and `Member.display_banner` properties.
2424
([#2556](https://github.com/Pycord-Development/pycord/pull/2556))
25-
- Added optional `check` parameter in `utils.basic_autocomplete`.
25+
- Added optional `filter` parameter in `utils.basic_autocomplete`.
2626
([#2590](https://github.com/Pycord-Development/pycord/pull/2590))
2727

2828
### Fixed

discord/utils.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,11 +1306,11 @@ def generate_snowflake(dt: datetime.datetime | None = None) -> int:
13061306
AV = Awaitable[V]
13071307
Values = Union[V, Callable[[AutocompleteContext], Union[V, AV]], AV]
13081308
AutocompleteFunc = Callable[[AutocompleteContext], AV]
1309-
CheckFunc = Callable[[AutocompleteContext, Any], Union[bool, Awaitable[bool]]]
1309+
FilterFunc = Callable[[AutocompleteContext, Any], Union[bool, Awaitable[bool]]]
13101310

13111311

13121312
def basic_autocomplete(
1313-
values: Values, *, check: CheckFunc | None = None
1313+
values: Values, *, filter: FilterFunc | None = None
13141314
) -> AutocompleteFunc:
13151315
"""A helper function to make a basic autocomplete for slash commands. This is a pretty standard autocomplete and
13161316
will return any options that start with the value from the user, case-insensitive. If the ``values`` parameter is
@@ -1323,9 +1323,9 @@ def basic_autocomplete(
13231323
values: Union[Union[Iterable[:class:`.OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`.AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
13241324
Possible values for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
13251325
single argument of :class:`.AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
1326-
check: Optional[Callable[[:class:`.AutocompleteContext`, Any], Union[:class:`bool`, Awaitable[:class:`bool`]]]]
1326+
filter: Optional[Callable[[:class:`.AutocompleteContext`, Any], Union[:class:`bool`, Awaitable[:class:`bool`]]]]
13271327
Predicate callable (sync or async) used to filter the autocomplete options. This function should accept two arguments:
1328-
the :class:`.AutocompleteContext` and an item from ``values``. If ``None`` is provided, a default check is used that includes items whose string representation starts with the user's input value, case-insensitive.
1328+
the :class:`.AutocompleteContext` and an item from ``values``. If ``None`` is provided, a default filter is used that includes items whose string representation starts with the user's input value, case-insensitive.
13291329
13301330
Returns
13311331
-------
@@ -1361,22 +1361,22 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V:
13611361
if asyncio.iscoroutine(_values):
13621362
_values = await _values
13631363

1364-
if check is None:
1364+
if filter is None:
13651365

1366-
def _check(ctx: AutocompleteContext, item: Any) -> bool:
1366+
def _filter(ctx: AutocompleteContext, item: Any) -> bool:
13671367
item = getattr(item, "name", item)
13681368
return str(item).lower().startswith(str(ctx.value or "").lower())
13691369

1370-
gen = (val for val in _values if _check(ctx, val))
1370+
gen = (val for val in _values if _filter(ctx, val))
13711371

1372-
elif asyncio.iscoroutinefunction(check):
1373-
gen = (val for val in _values if await check(ctx, val))
1372+
elif asyncio.iscoroutinefunction(filter):
1373+
gen = (val for val in _values if await filter(ctx, val))
13741374

1375-
elif callable(check):
1376-
gen = (val for val in _values if check(ctx, val))
1375+
elif callable(filter):
1376+
gen = (val for val in _values if filter(ctx, val))
13771377

13781378
else:
1379-
raise TypeError("``check`` must be callable.")
1379+
raise TypeError("``filter`` must be callable.")
13801380

13811381
return iter(itertools.islice(gen, 25))
13821382

0 commit comments

Comments
 (0)