-
Notifications
You must be signed in to change notification settings - Fork 21
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
adding type annotations and png example script #63
Conversation
Converted to draft to prevent merging, since this PR will help test new CI changes. |
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git" | ||
|
||
|
||
def load( | ||
file, *, bitmap, palette=None | ||
file: str, *, bitmap: BitmapConstructor, palette: PaletteConstructor = None | ||
): # pylint: disable=too-many-locals,too-many-branches |
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 have been researching a little about how to annotate the return type of this correctly, without assuming that we are always going to use the displayio.Bitmap
and displayio.Palette
. It seems like we can do this by using type aliases (https://peps.python.org/pep-0484/#type-aliases) to make sure the function returns the same type as the constructor that it gets, and optionally maybe protocols (https://peps.python.org/pep-0544/) to make sure those types have the required methods on them.
image, palette = adafruit_imageload.load("images/test_image.png") | ||
|
||
# Set the transparency index color to be hidden | ||
palette.make_transparent(0) |
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.
This is another todo – we could read the transparency information from the file, there are two kinds of chunks that can define that.
@deshipu are those comments gating merging this in? |
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.13.1 from 1.13.0: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#80 from BiffoBear/dhcp_error_handling Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.17.0 from 1.16.8: > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#63 from FoamyGuy/png_typing_and_example > Add .venv to .gitignore > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.4.6 from 3.4.5: > Merge pull request adafruit/Adafruit_CircuitPython_Motor#67 from tekktrik/pwmout-fix > Add .venv to .gitignore > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.12.12 from 1.12.11: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#124 from adafruit/chain-exception-when-fail > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Follow up on #61 to add typing annotations and an example of the new PNG loading functionality.