-
Notifications
You must be signed in to change notification settings - Fork 144
Open
Labels
feature requestRequest for a new featureRequest for a new feature
Description
Summary
Converters don't play nice with type checking. You can use Annotated
as a way to satisfy both.
What is the feature request for?
disnake.ext.commands
The Problem
You have to do some funky workarounds to make both the type checker and the converter happy.
Instead, the converter can be implied from the metadata (smilier to FastAPI.)
- url: ValidURL
+ url: Annotated[str, ValidURL]
The Ideal Solution
from .converters import ValidURL
class Foo(commands.Cog):
@commands.is_owner()
async def set_command(
self,
base_url: Annotated[str, ValidURL] = "",
) -> None: ...
This would let base_url
be a string while actually being converted in the background.
The Current Solution
Mock the type based on if TYPE_CHECKING
if TYPE_CHECKING:
Extension = str
else:
from monty.utils.converters import Extension
Code from monty python bot.
Additional Context
This change should be possible to make backwards compatible, since you would be inspecting the metadata of the object. But unsure since I am not familiar with this codebase enough.
Enegg
Metadata
Metadata
Assignees
Labels
feature requestRequest for a new featureRequest for a new feature