Skip to content

Commit 3fd939c

Browse files
cjwatsonJessicaTegner
andauthoredJan 8, 2025··
Fix convert_file for Python 3.13 (#384)
As of python/cpython#117589 (at least), `Path.glob` returns an `Iterator` rather than `Generator` (which inherits from `Iterator`). `convert_file` doesn't need to care about this distinction; it can reasonably accept both. This previously caused a test failure along these lines: ______________________________________________________ TestPypandoc.test_basic_conversion_from_file_pattern_pathlib_glob _______________________________________________________ self = <tests.TestPypandoc testMethod=test_basic_conversion_from_file_pattern_pathlib_glob> def test_basic_conversion_from_file_pattern_pathlib_glob(self): received_from_str_filename_input = pypandoc.convert_file("./*.md", 'html').lower() > received_from_path_filename_input = pypandoc.convert_file(Path(".").glob("*.md"), 'html').lower() tests.py:654: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ source_file = <map object at 0x7f83952c9420>, to = 'html', format = None, extra_args = (), encoding = 'utf-8', outputfile = None, filters = None, verify_format = True sandbox = False, cworkdir = '/home/cjwatson/src/python/pypandoc', sort_files = True [...] if not _identify_path(discovered_source_files): > raise RuntimeError("source_file is not a valid path") E RuntimeError: source_file is not a valid path pypandoc/__init__.py:201: RuntimeError Co-authored-by: Jessica Tegner <jessica@jessicategner.com>
1 parent 32d3a40 commit 3fd939c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎pypandoc/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, print_function, with_statement
33
from typing import Iterable
4+
from typing import Iterator
45
from typing import Union
5-
from typing import Generator
66

77
import os
88
import re
@@ -97,7 +97,7 @@ def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encodin
9797
cworkdir=cworkdir)
9898

9999

100-
def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:Union[str, None]=None,
100+
def convert_file(source_file:Union[list, str, Path, Iterator], to:str, format:Union[str, None]=None,
101101
extra_args:Iterable=(), encoding:str='utf-8', outputfile:Union[None, str, Path]=None,
102102
filters:Union[Iterable, None]=None, verify_format:bool=True, sandbox:bool=False,
103103
cworkdir:Union[str, None]=None, sort_files=True) -> str:
@@ -165,7 +165,7 @@ def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:U
165165
source_file = Path(source_file)
166166
elif isinstance(source_file, list):
167167
source_file = [Path(x) for x in source_file]
168-
elif isinstance(source_file, Generator):
168+
elif isinstance(source_file, Iterator):
169169
source_file = [Path(x) for x in source_file]
170170

171171

@@ -175,7 +175,7 @@ def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:U
175175
# if it is, just use the absolute path
176176
if isinstance(source_file, list):
177177
source_file = [x if x.is_absolute() else Path(cworkdir, x) for x in source_file]
178-
elif isinstance(source_file, Generator):
178+
elif isinstance(source_file, Iterator):
179179
source_file = (x if x.is_absolute() else Path(cworkdir, x) for x in source_file)
180180
# check ifjust a single path was given
181181
elif isinstance(source_file, Path):

0 commit comments

Comments
 (0)
Please sign in to comment.