adafruit / Adafruit_CircuitPython_Typing

Definitions not in the standard `typing` module that are needed for type annotation of CircuitPython code.
MIT License
6 stars 9 forks source link

Add type annotation protocols for LEDs #11

Closed tekktrik closed 2 years ago

tekktrik commented 2 years ago

Useful for typing LEDs without having to import them. Spawned from typing adafruit_esp32spi.

tekktrik commented 2 years ago

If this isn't widely used enough, I could also just type it in the relevant library

dhalbert commented 2 years ago

If this isn't widely used enough, I could also just type it in the relevant library

If it's used in more than one library, it's good to have it in a central place. Otherwise you can put the definitions inside the try block for the typing imports. They will take space in a library, which is one reason not to include them in libraries.

tekktrik commented 2 years ago

If they get caught (or missed, really) because of the try/except block, that should prevent them from using memory though, right? Either way, I'll try to raise it on a case-by-case basis then

dhalbert commented 2 years ago

Right, it's static code size, either in the filesystem, or in a frozen module.

tekktrik commented 2 years ago

Converted to draft for now. There may be other uses of this in the libraries but I'm not sure... I'll take a look and see if it's worth putting here or not!

tekktrik commented 2 years ago

Okay, I found at least a few libraries that use Protocol for LEDs in their library. Basing those types here seems to be a good idea in this case.

tekktrik commented 2 years ago

Looks like you'd need to define __getitem__ and/or __setitem__ in the protocol so yup!

tekktrik commented 2 years ago

@FoamyGuy do you know of any libraries that would need that set in the Protocol? I don't necessarily want to over constrain the protocols if where they are doesn't require that specific behavior (ex: the only need to generically describe fill()/color().)

tekktrik commented 2 years ago

Sounds good!