Skip to content

Commit 0e1351d

Browse files
committed
change to forward reference for possibly unbound objects in type hint(s)
1 parent 143beeb commit 0e1351d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

adafruit_ina219.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@
3333
from micropython import const
3434

3535
try:
36-
import typing
36+
from typing import TYPE_CHECKING
3737

38-
from busio import I2C
38+
if TYPE_CHECKING:
39+
from busio import I2C
3940
except ImportError:
40-
# define I2C to avoid the error:
41-
# def __init__(self, i2c_bus: I2C, addr: int = 0x40) -> None:
42-
# NameError: name 'I2C' is not defined
43-
I2C = None
41+
pass
4442

4543
__version__ = "0.0.0+auto.0"
4644
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_INA219.git"
@@ -153,7 +151,7 @@ class INA219:
153151
# raw_current RO : Current register (not scaled)
154152
# calibration RW : calibration register (note: value is cached)
155153

156-
def __init__(self, i2c_bus: I2C, addr: int = 0x40) -> None:
154+
def __init__(self, i2c_bus: "I2C", addr: int = 0x40) -> None:
157155
self.i2c_device = I2CDevice(i2c_bus, addr)
158156
self.i2c_addr = addr
159157

0 commit comments

Comments
 (0)