From f75922062dd4864d143902c0b6a6265a17e61811 Mon Sep 17 00:00:00 2001 From: Iurii Skorniakov <31827662+iurii-skorniakov@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:00:10 +0000 Subject: [PATCH] Python 3.10 breaking change for collections --- snaql/convertors.py | 7 +++++-- snaql/factory.py | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/snaql/convertors.py b/snaql/convertors.py index 2893630..1e158fc 100644 --- a/snaql/convertors.py +++ b/snaql/convertors.py @@ -1,7 +1,10 @@ # coding: utf-8 import re -import collections +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable ESCAPE_REGEX = re.compile(r"[\0\n\r\032\'\"\\]") ESCAPE_MAP = { @@ -119,7 +122,7 @@ def guard_case(value, items=None): return value items = items or set() - if not isinstance(items, collections.Iterable): + if not isinstance(items, Iterable): raise SnaqlGuardException('Guard items are not iterable') items = set(items) diff --git a/snaql/factory.py b/snaql/factory.py index ee33535..cd19792 100644 --- a/snaql/factory.py +++ b/snaql/factory.py @@ -1,7 +1,6 @@ # coding: utf-8 import os import copy -import collections import types import sys from collections import namedtuple @@ -13,6 +12,11 @@ from jinja2.utils import open_if_exists from schema import Schema +try: + from collections.abc import Callable, Iterable +except ImportError: + from collections import Callable, Iterable + from snaql.convertors import ( guard_bool, guard_case, @@ -175,7 +179,7 @@ def gen_func(self, name, meta_struct, env): def subrender_cond(owner_name, cond_func, context): if ( - isinstance(cond_func, collections.Callable) and + isinstance(cond_func, Callable) and cond_func.is_cond ): cond_struct = meta_struct['funcs'][cond_func.func_name] @@ -205,7 +209,7 @@ def fn(**kwargs): if maybe_cond_sql: kwargs[point] = maybe_cond_sql if ( - isinstance(val, collections.Iterable) and + isinstance(val, Iterable) and not isinstance( val, (str if PY3K else types.StringTypes, dict) )