-
Notifications
You must be signed in to change notification settings - Fork 187
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
typing(embeds): Retype embed methods to accept str instead of any #1201
Conversation
SupportsStr allows the typechecker to see if a class has implemented the __str__ magic method
Embed methods can now accept classs instances that have implemented the __str__ magic method as args
Document SupportsStr ABC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see much point in this. If the user is using a type checker, they would already see it only accepts str
. If they are not using a type checker, not noticing it is str
would also mean they do not notice SupportsStr
. Having to inherit an ABC removes almost all uses of a non-str argument that should already be str
anyway.
For attributes yes, but the methods do not strictly only take strings as they are typed with
This change is aimed towards people who use type checkers, as it is not enforced at runtime.
While I don't think of this as that big of an issue as the user can just convert any non-str arguments into strings using |
Because |
But what about any objects the user creates? Though looking back on it nextcord classes wont be accepted by the type checker as they don't inherit from
I have to disagree with this, I get this change is odd, I myself do not like it as it isn't a very clean solution, but this is the only solution I could come up with to close this issue. If you or anyone else have any ideas on how I can improve this pr I'm all ears, if not then this pr can be closed. |
Then I think they should be typed as
What I meant was that I could not think of any form of class which would satisfy |
I agree, this is probably the best solution, but would doing this still satisfy the issue? If so I'll push those changes. |
I mistook the But then I don't like this change because of programming ergonomics, à la "... if it quacks like a duck, then it probably is a duck": Overriding def __str__(self) -> str:
return repr(self) I think we have 2-3 possible options instead:
I think 2 or 3 is the right course of action here, while I'm personally leaning towards 2. |
Same here, 2 is probably the way to go. @EmreTech can I get your thoughts on which option would be best? (Apologies for the mention) |
I would go with option 3 since we're working on 3.0. Breaking changes don't matter all that much. |
Alright, I'll begin work on that then. |
It was decided to replace SupportsStr with str for practicality reasons, Internal str() conversions have also been removed as requested.
Forgot to mention but option 3 was implemented in the above commits, feel free to review. |
__str__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :D
Has decent testing been done on all modified functions and things that call them? I wouldn't be surprised if NC internally relies on |
I wasn't aware of any internals calling these functions, I'll look into it though, thanks. |
I'm unsure if anything calls them internally, just wanted to check if you looked into that already or not. Also, the PR summary probably should get updated? I'm not seeing a |
Yeah, I'll get on that soon. |
Looked into the internals as you requested, I didn't find any internal code calling these functions so this pr should be fine to merge. If i'm wrong and there are internals calling these functions, please do let me know. |
Alright, so I did find one slight issue. Super easy fix for people, just add Is passing an Asset object into |
I'm aware such a typing change would be breaking |
Thanks for informing me, I'll commit the fix soon.
I don't think there are any methods that strictly accept an Asset object for a: "image_url", "url" parameter. From what I know they accept str, so this pr shouldn't make embeds inconsistent. |
…on_url now gets passed the url instead of the Asset object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No longer applicable, SupportsStr
is no longer part of this PR.
Summary
Retypes embed methods to use
str
instead ofany
to improve typing and better reflect the docs.Closes issue #1076.
This is a Code Change
task pyright
and fixed the relevant issues.