Skip to content

Add typing to LEDs #30

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

Merged
merged 7 commits into from
Apr 28, 2023
Merged

Conversation

SebastienFauque
Copy link
Contributor

Adds typing to fancy Leds for most functions. This solves most cases for #24.

@SebastienFauque
Copy link
Contributor Author

SebastienFauque commented Apr 25, 2023

@FoamyGuy @tekktrik the function gamma_adjust is really complicated. Would you guys be able to take a look at how typing would work for this function?

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @SebastienFauque.

I had a look over it and have a few changes to recommend.

@@ -369,7 +386,9 @@ def mix(color1, color2, weight2=0.5):
GFACTOR = 2.7 # Default gamma-correction factor for function below


def gamma_adjust(val, gamma_value=None, brightness=1.0, inplace=False):
def gamma_adjust(
val: Any, gamma_value: Any = None, brightness: Any = 1.0, inplace=False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brightness can be typed float and inplace can be typed with bool

val and gamma_value might be able to have something more specific with Union and a few different types, but I'm not certain. I'd need to read over the docstring some more to grok the different modes of operation.

Copy link
Contributor

@FoamyGuy FoamyGuy Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't seen that you asked about this function in the other comment until after I posted these.

I'll try to take a closer look tomorrow and offer what guidance I can.

I think It's also okay if we're not 100% perfect on this round of typing, things can always be refined and improved as time goes on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FoamyGuy I've made the mentioned changes (made brightness obey the cases in the docstring) excluding the situation that will arise with the three unique cases on the gamma_adjust function. Case one and two are easy enough to solve, adding case 3 to the mix makes type hints difficult to build in and probably difficult for a newer user to understand.

If you have any more input on this I can go back and try to add the typing, or I can just keep it with Any.

@tekktrik tekktrik linked an issue Apr 27, 2023 that may be closed by this pull request
17 tasks
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks good to me now. Thanks again @SebastienFauque!

I think the way you've typed gamma_adjust is fine for now. The multiple modes of that function definitely make it tricky to have types for it. Perhaps someday it can be refactored and simplified.

@FoamyGuy FoamyGuy merged commit 7645421 into adafruit:main Apr 28, 2023
@SebastienFauque SebastienFauque deleted the feature/typingLEDs branch April 29, 2023 02:16
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 29, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI to 1.0.6 from 1.0.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_NeoPixel_SPI#36 from RossK1/adding_type_hints
  > Add upload url to release action
  > 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_PCF8563 to 2.0.0 from 1.0.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8563#6 from bablokb/4upstream
  > Add upload url to release action
  > 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_RGB_Display to 3.11.2 from 3.11.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#113 from tekktrik/fix/typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_FancyLED to 1.4.15 from 1.4.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_FancyLED#30 from SebastienFauque/feature/typingLEDs
  > Add upload url to release action
  > 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Type Annotations
2 participants