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 1/2] 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: From fc1e911ec83050893df1e1cfe2c259b8d5a2c2ee Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Sun, 9 Oct 2022 11:56:23 +0200 Subject: [PATCH 2/2] Update bib.py --- biblib/bib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/biblib/bib.py b/biblib/bib.py index a52a91b..9738778 100644 --- a/biblib/bib.py +++ b/biblib/bib.py @@ -91,9 +91,11 @@ def parse(self, str_or_fp_or_iter, name=None, *, log_fp=None): """ try: + # Python >= 3.10 from collections.abc import Iterable as collections_Iterable except AttributeError: - from collections import Iterable as collections_Iterable # does not work in python3.10 anymore + # Python < 3.10 + from collections import Iterable as collections_Iterable recoverer = messages.InputErrorRecoverer() if isinstance(str_or_fp_or_iter, str):