From c9b54431270f6b59a271203b42bcb2838e3140c5 Mon Sep 17 00:00:00 2001 From: MegaIng1 Date: Sat, 26 Sep 2020 21:12:12 +0200 Subject: [PATCH] Fix for python2.7 --- lark/load_grammar.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index bb5f71a..8849f76 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -663,17 +663,17 @@ def import_grammar(grammar_path, re_, base_paths=(), import_sources=()): if grammar_path not in _imported_grammars: import_paths = import_sources + base_paths + [stdlib_loader] for source in import_paths: - if isinstance(source, str): + if callable(source): with suppress(IOError): - joined_path = os.path.join(source, grammar_path) - with open(joined_path, encoding='utf8') as f: - text = f.read() + joined_path, text = source(base_paths, grammar_path) grammar = load_grammar(text, joined_path, re_, import_sources) _imported_grammars[grammar_path] = grammar break else: with suppress(IOError): - joined_path, text = source(base_paths, grammar_path) + joined_path = os.path.join(source, grammar_path) + with open(joined_path, encoding='utf8') as f: + text = f.read() grammar = load_grammar(text, joined_path, re_, import_sources) _imported_grammars[grammar_path] = grammar break