Add type stub for colour package - #15823
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I discovered |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The failing tests are caused by numpy, not my changes. |
|
Nevermind; different |
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
There was a problem hiding this comment.
Sorry for the delay. I few remarks below.
Just using set_hex_l = set_hex in the hex directly below the def set_hex... statement should work. If it doesn't I need to have a look at the exact error.
The way Color.__getattr__ and Color.__setattr__ work is better expressed using properties for type checking.
|
No worries, thanks for the review! I made all the requested changes. It turns out the stubtest error was being caused by the signature for set_hex_l lacking a |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This PR adds type stubs for the colour package.
There were a few small issues when writing the stubs that might need changes before merging:
colour.Color.set_hex_l, it said the runtime type wasCallable[[Any], Any]. I think that's becauseset_hex_lisn't defined as a method, but as a class variable with a lambda. I addedcolour.COlor.set_hex_lto the allowlistcolour.Color.__eq__'s implementation can return (not raise)NotImplemented. Mypy and pyright both disallow that, so I set a noqacolour.Color.hash_or_stroverload, saying overload 1 is wider than overload 2. However Hashable is narrower than object (setis object but not hashable), so that shouldn't be the case. I ignored with a noqa commentIf there are more idiomatic ways to fix any of those, let me know and I can make the changes.