adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.02k stars 1.19k forks source link

typing: Union type for 'any kind of display-like object' #7910

Open jepler opened 1 year ago

jepler commented 1 year ago

During PyCon sprints, a participant raised the issue of needing to type an argument as 'any kind of displayio display'. It would be nice if the core (or maybe circuitpython-typing?) had a Union type that included all these types, for libraries to refer to.

tekktrik commented 1 year ago

circuitpython_typing could add a typing.Protocol for displays (or multiple kinds) if we want to duck type it. Can you link to an example of where it would be used to know what methods/attributes are required?

jepler commented 1 year ago

I didn't take note of which repo the author was working on. However, adafruit_bitmapsaver looks like one such:

def save_pixels(                                                                
    file_or_filename: Union[str, BufferedWriter],                               
    pixel_source: Union[Display, Bitmap] = None,                                
    palette: Optional[Palette] = None,                                          
) -> None:                                                                      
tekktrik commented 1 year ago

Assigning to myself so I don't forget about this!