From b272b5e124feb5142bf512ba49bbb4a534cab469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Wi=C3=9Fmann?= Date: Thu, 16 Dec 2021 22:16:56 +0100 Subject: [PATCH] Add compatibility to python 3.10 This makes biblib work with python 3.10. The Parser.parse() uses collections.abc per default (which is the only way in python 3.10) and only falls back to the old collections.Iterable if collections.abc does not exist. --- biblib/bib.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/biblib/bib.py b/biblib/bib.py index 495ab87..a52a91b 100644 --- a/biblib/bib.py +++ b/biblib/bib.py @@ -90,11 +90,16 @@ def parse(self, str_or_fp_or_iter, name=None, *, log_fp=None): defined in earlier files. """ + try: + from collections.abc import Iterable as collections_Iterable + except AttributeError: + from collections import Iterable as collections_Iterable # does not work in python3.10 anymore + recoverer = messages.InputErrorRecoverer() if isinstance(str_or_fp_or_iter, str): self.__data = str_or_fp_or_iter fname = name or '' - elif isinstance(str_or_fp_or_iter, collections.Iterable) and \ + elif isinstance(str_or_fp_or_iter, collections_Iterable) and \ not hasattr(str_or_fp_or_iter, 'read'): for obj in str_or_fp_or_iter: with recoverer: