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
Explicit convert color to string when compile resources #4997
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4997 +/- ##
==========================================
+ Coverage 85.72% 87.43% +1.71%
==========================================
Files 586 586
Lines 49498 49538 +40
==========================================
+ Hits 42430 43314 +884
+ Misses 7068 6224 -844
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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 to me.
Not that calling str
on a Pydantic Color
will return the color name (e.g. cornflowerblue) if its value corresponds to one the known named colors, and otherwise it will return the the hex string that represents the color value.
Based on my understanding Pydantic supports color names (e.g. cornflowerblue) based on the CSS3 spec and Qt supports color names based on the SVG 1.0 spec, and these are identical.
If you wanted to bypass that explanation to anyone else, you could use Color.as_hex
which will always return the hex string (or maybe Color.as_rgb
which returns the rgb(a) string). But I don't feel strongly here. I'd also be fine with changing type annotations from str
to Color
.
This pr reproduce current behaviour when we do implicit conversion by passing color as |
Understood. Just pointing out that the behavior of string conversion for Pydantic's |
@andy-sweet I see you have approved - would you suggest that we switch to always using hex codes or keep the current behaviour in this PR? Marked as 'merge for 0.4.17'! |
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 don't have any particular preference on use to_hex or str(color).
My thought is that any weird case heisenbug due to str() might be harder to debug and https://en.wikipedia.org/wiki/Robustness_principle
says "be conservative in what you send, be liberal in what you accept", so maybe a small pref on to_hex, but I think the change we hit a corner case if really small.
I agree, there's no need to be magic where users are not involved; I vote for |
Multi-approved and simple change. Merging! |
Description
One of the big problems when debugging #4995 for me was that
get_colorized_svg
signature expects color to be a string, and we passpydantic.color.Color
to it. So I lost time digging into what could go wrong and why we passed unexpected arguments.As follow up we could simply convert color to string before this phase (what is done in this PR) or update the signature of
get_colorized_svg
to assume that we could acceptColor
class also to convert it into a string later.I personally prefer the conversion way, but if you think of another way, the signature update is also ok.
Type of change
References
How has this been tested?
as there are small differences between the two Qt bindings.
Final checklist:
trans.
to make them localizable.For more information see our translations guide.