From 36282bafd261214838d03d84c5c69564b2e173c3 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Tue, 5 Jul 2022 23:40:42 -0400
Subject: [PATCH] Correct import error with Python < 3.9

I thought I checked this already, but I guess not.
---
 django_dump_die/constants.py             | 10 ++++++++--
 django_dump_die/views/example_helpers.py | 11 ++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/django_dump_die/constants.py b/django_dump_die/constants.py
index d0d9f11..7c60ff1 100644
--- a/django_dump_die/constants.py
+++ b/django_dump_die/constants.py
@@ -2,7 +2,11 @@
 
 import datetime
 import types
-import zoneinfo
+try:
+    from zoneinfo import ZoneInfo
+    ZONEINFO_PRESENT = True
+except ImportError:
+    ZONEINFO_PRESENT = False
 
 from decimal import Decimal
 
@@ -36,7 +40,6 @@ INTERMEDIATE_TYPES = [
     datetime.time,
     datetime.timedelta,
     timezone.timezone,
-    zoneinfo.ZoneInfo,
 
     PosixPath,
     PurePath,
@@ -44,6 +47,9 @@ INTERMEDIATE_TYPES = [
     PureWindowsPath,
 ]
 
+if ZONEINFO_PRESENT:
+    INTERMEDIATE_TYPES.append(zoneinfo.ZoneInfo)
+
 
 # List of additional simple types defined as strings that do not need to be recursively inspected.
 ADDITIONAL_SIMPLE_TYPES = getattr(settings, 'DJANGO_DD_ADDITIONAL_SIMPLE_TYPES', [])
diff --git a/django_dump_die/views/example_helpers.py b/django_dump_die/views/example_helpers.py
index 5455d62..0a7172e 100644
--- a/django_dump_die/views/example_helpers.py
+++ b/django_dump_die/views/example_helpers.py
@@ -16,7 +16,8 @@ from django.forms import ModelForm
 from django.utils import timezone
 from pathlib import Path, PosixPath, PurePath, WindowsPath
 from types import ModuleType
-from zoneinfo import ZoneInfo
+
+from django_dump_die.constants import ZONEINFO_PRESENT
 
 
 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -398,8 +399,6 @@ def dump_intermediate_types():
 
     dump_datetime_types()
 
-    from pathlib import Path, PosixPath, PurePath, WindowsPath
-
     # Generate variables to dump.
     sample_pure_path = PurePath(Path.cwd())
     try:
@@ -602,7 +601,8 @@ def dump_datetime_types():
     sample_dt_timedelta = timedelta(days=1)
     sample_tz_timedelta = timezone.timedelta(days=2)
     sample_pytz_timezone = pytz.timezone('UTC')
-    sample_zoneinfo_timezone = ZoneInfo('UTC')
+    if ZONEINFO_PRESENT:
+        sample_zoneinfo_timezone = ZoneInfo('UTC')
 
     # Call dump on all generated variables.
     dump('')
@@ -616,7 +616,8 @@ def dump_datetime_types():
     dump(sample_dt_timedelta)
     dump(sample_tz_timedelta)
     dump(sample_pytz_timezone)
-    dump(sample_zoneinfo_timezone)
+    if ZONEINFO_PRESENT:
+        dump(sample_zoneinfo_timezone)
 
 
 def dump_model_types():
-- 
GitLab