Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid error when microcontroller>Pin import fails #93

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 1 commit into from
Oct 23, 2023

Conversation

ilario
Copy link
Contributor

@ilario ilario commented Oct 19, 2023

When running

>>> from adafruit_ads1x15.analog_in import AnalogIn

without having python3-libgpiod installed, I got this not-very-clear error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/adafruit_ads1x15/analog_in.py", line 16, in <module>
    from .ads1x15 import ADS1x15
  File "/usr/local/lib/python3.9/dist-packages/adafruit_ads1x15/ads1x15.py", line 58, in <module>
    class ADS1x15:
  File "/usr/local/lib/python3.9/dist-packages/adafruit_ads1x15/ads1x15.py", line 142, in ADS1x15
    def read(self, pin: Pin, is_differential: bool = False) -> int:
NameError: name 'Pin' is not defined

This happens because the import of microcontroller > Pin here

try:
from typing import Dict, List, Optional
from busio import I2C
from microcontroller import Pin
except ImportError:
pass

is failing due to the lack of python3-libgpiod. And the actually useful error message is not shown as it gets caught by try, which is ok, as microcontroller>Pin is not needed for running the thing.

The error I observed is caused by the mention of Pin here:

def read(self, pin: Pin, is_differential: bool = False) -> int:

def _read(self, pin: Pin) -> int:

No idea why the Python interpreter (I am on Python 3.9.2) cares about the type hints.

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.

Thank you.

@FoamyGuy FoamyGuy merged commit bb6ee16 into adafruit:main Oct 23, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 31, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 2.2.24 from 2.2.23:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#93 from ilario/Pin

Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO055 to 5.4.12 from 5.4.11:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO055#119 from CedarGroveStudios/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_PN532 to 2.4.0 from 2.3.20:
  > Merge pull request adafruit/Adafruit_CircuitPython_PN532#66 from symm/mifare-value-block

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.4.3 from 7.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#179 from vladak/handle_on_message_vs_self

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.

2 participants