Skip to content
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

Improve type validation error messages, especially for pins #7437

Merged
merged 1 commit into from Jan 11, 2023

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Jan 10, 2023

Fixes #7238, but does a lot more also.

  • Per @jepler's suggestion, expands %q must be of type %q to %q must be of type %q, not %q.
  • Adds a new validator for objects in a collection: object in %q must be of type %q, not %q. Used a lot for pin lists.
  • Adds arg_name to a lot of pin validation routines.
  • Adds arg_name to SPI bus validation routine.
  • Adds arg_name to cp_enum_value to use when validation fails.
  • Replaces some Expected ... messages with standard type validation messages.
  • Consolidated some %q must be %q or None and %q must be %q or %q to all be %q must be %q or %q, not %q.
  • Standardized a few other error messages to reduce the number of messages.
  • Removed redundant type validations in esp32_camera/__init__.c.
  • Removed redundant type validations in aesio/aes.c and did some minor cleanup.
  • Minor cleanup in espulp/ULP.c.
  • Minor rework of sequential pin checking in rp2pio.

Examples:

>>> busio.I2C(1.0, 2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: scl must be of type Pin, not float
>>> keypad.Keys([34,52], value_when_pressed=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object in row_pins must be of type Pin, not int

This is all probably a net size increase, but hopefully not too much.

@dhalbert dhalbert requested a review from jepler January 10, 2023 19:12
@dhalbert dhalbert force-pushed the improve-type-checking-error-msgs branch 4 times, most recently from 6cb9519 to 641ff5c Compare January 10, 2023 20:00
@dhalbert dhalbert force-pushed the improve-type-checking-error-msgs branch from 641ff5c to a974402 Compare January 10, 2023 20:03
@tannewt tannewt requested review from tannewt and removed request for jepler January 11, 2023 18:45
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for improving error messages!

@tannewt tannewt merged commit 78c2fa5 into adafruit:main Jan 11, 2023
@dhalbert dhalbert deleted the improve-type-checking-error-msgs branch January 12, 2023 02:42
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.

PWMOut Error on Raspberry Pi Pico W
2 participants