Skip to content

refactor: Options#3126

Draft
Soheab wants to merge 20 commits into
Pycord-Development:masterfrom
Soheab:refactor/options
Draft

refactor: Options#3126
Soheab wants to merge 20 commits into
Pycord-Development:masterfrom
Soheab:refactor/options

Conversation

@Soheab
Copy link
Copy Markdown
Contributor

@Soheab Soheab commented Feb 26, 2026

Summary

Overrides #2919

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.
  • AI Usage has been disclosed.
    • If AI has been used, I understand fully what the code does

@pycord-app
Copy link
Copy Markdown

pycord-app Bot commented Feb 26, 2026

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/3126/head:pr-3126
git checkout pr-3126

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3126/head

@Paillat-dev

This comment has been minimized.

@Soheab

This comment has been minimized.

@Lulalaby

This comment has been minimized.

Comment thread discord/commands/_options.py Outdated
Comment on lines +44 to +47
if sys.version_info >= (3, 12):
from typing import TypeAliasType
else:
from typing_extensions import TypeAliasType
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should always import from typing_extension to avoid potentially differing behavior, also haven't seen this kind of version check myself yet in the lib so idk

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here specifically I don't think it works, bc we do instance checks on it. Could you confirm that @Soheab ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current code fwiw, new code is in the options.py module.

@Lulalaby Lulalaby added this to Pycord Mar 18, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Pycord Mar 18, 2026
@Lulalaby Lulalaby force-pushed the master branch 2 times, most recently from 25347b5 to cc6ebbb Compare April 14, 2026 09:00
@Paillat-dev Paillat-dev force-pushed the master branch 2 times, most recently from 45025bd to 01e9fa8 Compare April 14, 2026 10:21
@Paillat-dev Paillat-dev changed the title Refactor/options refactor: Options May 29, 2026
Copy link
Copy Markdown
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you find there are some patterns here that we have to support but are clearly sub-optimal either from user side or from our need of handling it, you can deprecate them.

Comment thread discord/commands/core.py
return get_origin(annotation) is Annotated
return list(final_options.values())

# def _match_option_param_names(self, params, options):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code

Comment thread discord/commands/core.py

return as_dict

async def _invoke(self, ctx: ApplicationContext) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this function is still a mess, but I get out of scope

@@ -1,52 +1,24 @@
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this was on putpose

Comment on lines +52 to +55
PY_310 = sys.version_info >= (3, 10) # for UnionType
PY_311 = sys.version_info >= (3, 11) # for StrEnum

__all__ = (
"ThreadOption",
"Option",
"OptionChoice",
"option",
)
PY_314 = sys.version_info >= (3, 14)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forr ?


T = TypeVar("T", bound=AutocompleteReturnType)
MaybeAwaitable = T | Awaitable[T]
AutocompleteFunction = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking these might maybe use Protocols instead of unions like this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for the record I acknowledge it's my fault, I made these).

input_type: ValidOptionType = str,
/,
*,
parameter_name: str | None = None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is the occasion to use some kind of Unpack TypedDict if you want to, since you're fundamentally refactoring it.

return inner


def options(**options: Option) -> Callable[[CallableT], CallableT]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this new ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Allows users to specify metadata for multiple params at once.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be neat if this accepted a dict | Option then I feel like not just an already-built Option. Basically like using @option multiple times. Either way, good idea and addition

@Paillat-dev
Copy link
Copy Markdown
Member

Also if you want to feel free to add some tests. Trying to do it for bigger refactors (see command sync).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Passing choices= to an option and typing it as Literal fails Parse the args better

4 participants