Skip to content

Commit f88349e

Browse files
committed
Fix Union types
1 parent 24a4c6c commit f88349e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

adafruit_dht.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import time
3131
from os import uname
3232
from digitalio import DigitalInOut, Pull, Direction
33-
from microcontroller import Pin
3433

3534
_USE_PULSEIO = False
3635
try:
@@ -40,6 +39,12 @@
4039
except (ImportError, NotImplementedError):
4140
pass # This is OK, we'll try to bitbang it!
4241

42+
try:
43+
# Used only for typing
44+
from typing import Union
45+
from microcontroller import Pin
46+
except ImportError:
47+
pass
4348

4449
__version__ = "0.0.0-auto.0"
4550
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git"
@@ -61,8 +66,8 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool):
6166
self._pin = pin
6267
self._trig_wait = trig_wait
6368
self._last_called: float = 0
64-
self._humidity: int | float | None = None
65-
self._temperature: int | float | None = None
69+
self._humidity: Union[int, float, None] = None
70+
self._temperature: Union[int, float, None] = None
6671
self._use_pulseio = use_pulseio
6772
if "Linux" not in uname() and not self._use_pulseio:
6873
raise Exception("Bitbanging is not supported when using CircuitPython.")
@@ -198,8 +203,8 @@ def measure(self) -> None:
198203
):
199204
self._last_called = time.monotonic()
200205

201-
new_temperature: int | float = 0
202-
new_humidity: int | float = 0
206+
new_temperature: Union[int, float] = 0
207+
new_humidity: Union[int, float] = 0
203208

204209
if self._use_pulseio:
205210
pulses = self._get_pulses_pulseio()
@@ -251,7 +256,7 @@ def measure(self) -> None:
251256
self._humidity = new_humidity
252257

253258
@property
254-
def temperature(self) -> int | float | None:
259+
def temperature(self) -> Union[int, float, None]:
255260
"""temperature current reading. It makes sure a reading is available
256261
257262
Raises RuntimeError exception for checksum failure and for insufficient
@@ -261,7 +266,7 @@ def temperature(self) -> int | float | None:
261266
return self._temperature
262267

263268
@property
264-
def humidity(self) -> int | float | None:
269+
def humidity(self) -> Union[int, float, None]:
265270
"""humidity current reading. It makes sure a reading is available
266271
267272
Raises RuntimeError exception for checksum failure and for insufficient

0 commit comments

Comments
 (0)