Skip to content

Conversation

pantheraleo-7
Copy link
Contributor

@pantheraleo-7 pantheraleo-7 commented Dec 7, 2024

Addresses #100

If the PR gets accepted, I'll be willing to update examples, docs, etc.

Per this PR, the usage example would like this:

import board
from adafruit_ads1x15 import ADS1115, AnalogIn, ads1x15

i2c = board.I2C()
ads = ADS1115(i2c)
chan = AnalogIn(ads, ads1x15.Pin.A0)

I'd say this is more pythonic and readable. This change is completely backwards compatible.

@pantheraleo-7
Copy link
Contributor Author

Hmm.. seems like pylint doesn't recognise redundant aliases. Ruff, pyflake, etc. recommend redundant aliases for re-exports.

@pantheraleo-7 pantheraleo-7 marked this pull request as ready for review April 6, 2025 07:55
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.

@pantheraleo-7 Thanks for submitting this. Sorry it took so long to get a review / response.

I have a few other comments with suggested changes.

I also think this same PR should go ahead and remove the original P0 etc... duplicated constants and update the examples and readme.

@pantheraleo-7 pantheraleo-7 force-pushed the main branch 2 times, most recently from 8679931 to 0b7816c Compare October 3, 2025 16:02
@pantheraleo-7 pantheraleo-7 requested a review from FoamyGuy October 4, 2025 02:32
@pantheraleo-7 pantheraleo-7 changed the title draft: re-export symbols (classes, constants) to accessible & ergonomic locations re-export symbols (classes, constants) to accessible & ergonomic locations Oct 4, 2025
@pantheraleo-7 pantheraleo-7 force-pushed the main branch 2 times, most recently from 4d17126 to 0b7816c Compare October 4, 2025 02:51
@pantheraleo-7 pantheraleo-7 reopened this Oct 4, 2025
# define Pin to avoid the error:
# def read(self, pin: Pin, is_differential: bool = False) -> int:
# NameError: name 'Pin' is not defined
Pin = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see this pattern in many libraries which is flat out wrong and results in more type checking errors. The correct solution is forward references, see ads1x15.py diff#130/139.

Also, ideally, the imports should be guarded by a if typing.TYPE_CHECKING block but it isn't strictly necessary since the imports are already in a try-except block but the former is more pythonic and correct.

So the full correct pattern to use here is:

try:
    from typing import TYPE_CHECKING  # and other `typing` imports
    if TYPE_CHECKING:
        # imports from modules other than `typing` will come here
except ImportError:
    pass

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 some more. One more question, and request to update the docstrings to match new type annotations.

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 looks good to me.

I tested the latest version using simpletest script and a potentiometer connected to A0.

This will need some guide updates when merged. At least on this page: https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/python-circuitpython perhaps others since this library supports multiple different breakouts. I'll do a more thorough sweep and update all required pages when I merge this.

@FoamyGuy FoamyGuy merged commit 09f7128 into adafruit:main Oct 9, 2025
1 check passed
@FoamyGuy
Copy link
Contributor

FoamyGuy commented Oct 9, 2025

The learn page linked above is updated now to reflect the changes from this PR.

I searched learn repo and site for any other usages of ADS1x15 library and did not find any.

adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 10, 2025
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.

2 participants