feat: make context have generic client types #1699
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Description
This PR makes the contexts a generic type holding
ClientT
, aTypeVar
that represents clients and subclasses. Taking advantage of PEP 696, this PR ensures a grand total of 0 typings are broken by usingdefault
(thanks totyping_extensions
).This allows for people to type out their command functions in a pretty clean way if they make a subclass of
Client
- previously, you would have to make your ownContext
class that replaced theClient
references with your own, but now it's as easy as the test scenario.This doesn't cover every possible thing that could use
ClientT
, and especially not everything that could useTypeVar(default=X)
, but it's a startChanges
ClientT
inconst
. To get around circular imports, during runtime, allClientT
is isClientT = TypeVar("ClientT")
, but when type checking, it's far more accurate.ClientT
in theContext
s as a generic.Client
's custom contexts to use the new generic property.Related Issues
Test Scenarios
Python Compatibility
3.10.x
3.11.x
Checklist
pre-commit
code linter over all edited files