From 52458fed14d73c25fa2093c3a27c8a62f58762f3 Mon Sep 17 00:00:00 2001 From: Michal Horejsek Date: Wed, 27 Nov 2024 21:44:35 +0100 Subject: [PATCH] Add re import when using regex pattern --- CHANGELOG.txt | 1 + fastjsonschema/draft04.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a21854d..e43dbb1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ * Fixed detecting when infinity is reached with multipleOf * Fixed that min/max items/lenght/properties can be float * Fixed that everything with empty `not` is invalid +* Fixed missing re import when using regex pattern * Improved regexp for email format to comfort test suite * Improved regexp for date format to comfort test suite * Improved regexp for ipv4 format to comfort test suite diff --git a/fastjsonschema/draft04.py b/fastjsonschema/draft04.py index 6feda8b..d8af14b 100644 --- a/fastjsonschema/draft04.py +++ b/fastjsonschema/draft04.py @@ -271,6 +271,7 @@ def generate_format(self): self._generate_format(format_, format_ + '_re_pattern', format_regex) # Format regex is used only in meta schemas. elif format_ == 'regex': + self._extra_imports_lines = ['import re'] with self.l('try:', optimize=False): self.l('re.compile({variable})') with self.l('except Exception:'):