-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type nextcord.Embed method parameters more specifically #1076
Comments
I'm not sure if a protocol would fit in this situation, as you know every class in python can be converted into a str with or without manually implementing the str magic method as python will just default to repr if str is not implemented, and that's where the issue is. It's impossible to tell if it is implemented or not with protocols as to protocols str is always defined. But I am aware of one way of achieving this, what we can do instead is make use of an ABC with just the str magic method as an abstract method, but this comes with its own drawbacks such as, forcing the ABC to be inherited by the user's classes and it not supporting literal strings, so the typing would need to be a union of the ABC and str. If you are fine with me using the above method, I wouldn't mind submitting a pr to resolve your issue. |
Forgot to mention this in my last message but the user wont be able to pass raw numbers and such as arguments. So they'll need to convert those values into strings using If you're fine with that, feel free to assign me to this issue. I'm down to implement it. |
Yeah, I think that's a fair compromise. |
Summary
The methods for
nextcord.Embed
should have properly typed parameters.What is the feature request for?
The core library
The Problem
Currently, many of the parameters in
nextcord.Embed
methods that are supposed to bestr
are typed withAny
. This is not ideal because static type checkers will allow you to provide any object, whether it's appropriate for the method. It's like that so the parameters can support any object then be stringified later, but it could lead to weird problems if not used correctly.Here's an example of this:
nextcord/nextcord/embeds.py
Line 324 in dcadc7e
The Ideal Solution
nextcord.Embed
methods should be typed more precisely to only allow objects that support conversion tostr
. For example, in our example methodset_footer
, if an object that supports conversion to a string (__str__
) is provided, then the type checker will be happy. Otherwise, it will throw an error.This can be accomplished by typing the parameter with a protocol that lists the supported conversion method. Unfortunately, Python does not have a built-in protocol for conversion to a string because technically every object can be converted to a string. We will have to make our own.
The Current Solution
No response
Additional Context
As discussed on the Discord Server, this issue will be for v3.
The text was updated successfully, but these errors were encountered: