Replies: 2 comments 8 replies
-
Hi @ccprince ! Thank you for starting this discussion. You bring up a good point. The type hints in py5 could include classes from the optional dependencies such as the library colour. I'll open an issue to track this. This is also related to something @villares and I have previously discussed, in that methods like Getting this to work would be tricky. One complexity is that most of the py5 code is not written directly. It is generated by py5generator using metadata about the methods and variables. Getting these type hints added would have to be done in a way that fits in that workflow. Your proof of concept above is part of a solution but I would need to figure out how to get py5generator to create the overloads like that for it to work for all methods. And I don't have time for that right now, as I have a show opening in a few weeks. Let's open an issue for now so I don't forget and I will revisit it later when I have more flexibility. |
Beta Was this translation helpful? Give feedback.
-
OK, I poked around a little bit in the generator, and I'll clearly need to put in more time before I can even think about adding any code to it. So, instead, I've got a kludge. In some ways, it's kludgier than just manually hacking on the generated code, but I won't have to re-hack it after each release, or in each venv.
That
This makes the sketch code a little less consistent, but it gets rid of the ugly and incorrect errors. It's a reasonable trade-off, for now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I try to use
colour.Color
I'm getting errors in VSCode:OK, it's not really an error, but rather Pylance trying to save me from mistakes. The code works just fine, it's the type hinting that doesn't know about
Color
.I first tried turning off that
reportCallIssue
check, but then it complained about the type of the parameter. Turning that check off really defeats the purpose of the type hints, all together.So, as a proof of concept, I bashed this into
py5/__init__.py
:And that gets rid of the error cleanly.
Obviously, this is just a quality-of-life improvement, so I can't imagine it would be high on the list of development priorities. Should I make up a PR? My plan would be to add that new
@overload
definition, along with a copy of the relevant doc string, on all the methods that rely on@_convert_hex_color()
.Beta Was this translation helpful? Give feedback.
All reactions