Skip to content

Define I2C if busio.I2C import fails #39

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ilario
Copy link

@ilario ilario commented Mar 27, 2025

busio.I2C gets imported only for the type hint here:

class INA219:
    [...]
    def __init__(self, i2c_bus: I2C, addr: int = 0x40) -> None:

If the import of busio.I2C fails, then the definition of INA219 fails with:

NameError: name 'I2C' is not defined

So, instead of passing, I assign a None value to I2C simply for avoiding that error.

This PR is similar to this one done for another module: adafruit/Adafruit_CircuitPython_ADS1x15#93

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.

1 participant