Skip to content

Conversation

afroemming
Copy link
Contributor

@afroemming afroemming commented Jun 14, 2023

Summary

Resolves #2120. These changes allow options definitions of the form:

some_int: Annotated[int, Option(description="Tell me an integer")]

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.

* Adds function for checking if a parameter is annotated by form
typing.Annotated.
* Adds conditional block to parse parameter annotation if that check is
true.
@afroemming
Copy link
Contributor Author

I'm not sure how/ where to update documentation, but I can try if given advice.

@Lulalaby Lulalaby added this to the v2.5 milestone Jun 14, 2023
@Lulalaby Lulalaby added priority: low Low Priority status: awaiting review Awaiting review from a maintainer feature Implements a feature labels Jun 14, 2023
@afroemming afroemming changed the title Handle typing annotated feat: handle typing.Annotated form annotations in slash commands option parser. Jun 14, 2023
@JustaSqu1d JustaSqu1d added the hold: changelog This pull request is missing a changelog entry label Jun 14, 2023
@afroemming
Copy link
Contributor Author

Ah, didn't see Pycord targets minimum python version 3.8. These changes support/ require 3.9 changes.

@EmmmaTech
Copy link
Contributor

EmmmaTech commented Jun 15, 2023

Ah, didn't see Pycord targets minimum python version 3.8. These changes support/ require 3.9 changes.

You should import Annotated from typing_extensions instead of typing to support 3.8.

@Lulalaby Lulalaby enabled auto-merge (squash) June 15, 2023 01:07
@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #2124 (0fe9265) into master (715a3f5) will increase coverage by 0.76%.
The diff coverage is 89.70%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2124      +/-   ##
==========================================
+ Coverage   33.11%   33.87%   +0.76%     
==========================================
  Files          97      109      +12     
  Lines       19151    22340    +3189     
==========================================
+ Hits         6342     7568    +1226     
- Misses      12809    14772    +1963     
Flag Coverage Δ
macos-latest-3.10 33.85% <89.70%> (+0.75%) ⬆️
macos-latest-3.11 33.85% <89.70%> (+0.75%) ⬆️
macos-latest-3.8 33.86% <89.70%> (+0.75%) ⬆️
macos-latest-3.9 33.86% <89.70%> (+0.75%) ⬆️
ubuntu-latest-3.10 33.85% <89.70%> (+0.75%) ⬆️
ubuntu-latest-3.11 33.85% <89.70%> (+0.75%) ⬆️
ubuntu-latest-3.8 33.86% <89.70%> (+0.75%) ⬆️
ubuntu-latest-3.9 33.86% <89.70%> (+0.75%) ⬆️
windows-latest-3.10 33.85% <89.70%> (+0.75%) ⬆️
windows-latest-3.11 33.85% <89.70%> (+0.75%) ⬆️
windows-latest-3.8 33.86% <89.70%> (+0.75%) ⬆️
windows-latest-3.9 33.86% <89.70%> (+0.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tests/test_typing_annotated.py 87.50% <87.50%> (ø)
discord/commands/core.py 40.52% <100.00%> (+22.74%) ⬆️

... and 22 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 715a3f5...0fe9265. Read the comment docs.

@Lulalaby Lulalaby requested review from FrostByte266, BobDotCom and a team and removed request for CodeWithSwastik June 15, 2023 01:17
@Lulalaby Lulalaby merged commit d894a58 into Pycord-Development:master Jun 15, 2023
@afroemming afroemming deleted the handle-typing-annotated branch June 15, 2023 21:53
afroemming added a commit to afroemming/pycord that referenced this pull request Jun 16, 2023
Pycord requires typing_extensions as a dependency for python < 3.11,
however not on version >= 3.11. Because the changes in the referenced
pull always tries to load from typing_extensions, they make it so an
exception will be raised if the end user is using python >= 3.11 and
does not otherwise have that library install, an exception will occur
when _parse_options is run (ie, whenever a command is registered.)

This change checks the version of python running Pycord, then imports
stdlib typing if >= 3.11.
afroemming added a commit to afroemming/pycord that referenced this pull request Jun 16, 2023
Pycord requires typing_extensions as a dependency for python < 3.11,
however not on version >= 3.11. Because the changes in the referenced
pull always tries to load from typing_extensions, they make it so an
exception will be raised if the end user is using python >= 3.11 and
does not otherwise have that library installed when _parse_options is
 run (ie, whenever a command is registered).

This change checks the version of python running Pycord, then imports
stdlib typing if >= 3.11.
Lulalaby pushed a commit that referenced this pull request Jun 16, 2023
Pycord requires typing_extensions as a dependency for python < 3.11,
however not on version >= 3.11. Because the changes in the referenced
pull always tries to load from typing_extensions, they make it so an
exception will be raised if the end user is using python >= 3.11 and
does not otherwise have that library installed when _parse_options is
 run (ie, whenever a command is registered).

This change checks the version of python running Pycord, then imports
stdlib typing if >= 3.11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Implements a feature hold: changelog This pull request is missing a changelog entry priority: low Low Priority status: awaiting review Awaiting review from a maintainer
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Allow typing.Annotated hints for defining options.
5 participants