From 5ba65950bdca7e7a7520869df87f398cffbbe585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 27 Jun 2024 18:30:55 +0200 Subject: [PATCH 1/3] cli: Fix docstring processing with Python 3.13+ Fix docstring processing code to reindent the docstrings if using Python 3.13 or newer. Starting with this version, all docstrings are automatically dedented by Python, which causes the regular expression to fail to match. Fixes #1585 --- tqdm/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tqdm/cli.py b/tqdm/cli.py index 7284f28d..1bbce6d1 100644 --- a/tqdm/cli.py +++ b/tqdm/cli.py @@ -4,6 +4,7 @@ Module version for monitoring CLI pipes (`... | python -m tqdm | ...`). import logging import re import sys +import textwrap from ast import literal_eval as numeric from .std import TqdmKeyError, TqdmTypeError, tqdm @@ -177,7 +178,11 @@ def main(fp=sys.stderr, argv=None): logging.basicConfig(level=getattr(logging, logLevel), format="%(levelname)s:%(module)s:%(lineno)d:%(message)s") - d = tqdm.__doc__ + CLI_EXTRA_DOC + d = tqdm.__doc__ + if sys.version_info >= (3, 13): + # Python 3.13+ automatically dedents docstrings + d = textwrap.indent(d, " ") + d += CLI_EXTRA_DOC opt_types = dict(RE_OPTS.findall(d)) # opt_types['delim'] = 'chr' From 43230f6095a1ab5068481d543dc7ec3a60a3c08b Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 3 Aug 2024 22:36:53 +0100 Subject: [PATCH 2/3] slight lint --- tqdm/cli.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tqdm/cli.py b/tqdm/cli.py index 1bbce6d1..d681b164 100644 --- a/tqdm/cli.py +++ b/tqdm/cli.py @@ -4,8 +4,8 @@ Module version for monitoring CLI pipes (`... | python -m tqdm | ...`). import logging import re import sys -import textwrap from ast import literal_eval as numeric +from textwrap import indent from .std import TqdmKeyError, TqdmTypeError, tqdm from .version import __version__ @@ -178,11 +178,9 @@ def main(fp=sys.stderr, argv=None): logging.basicConfig(level=getattr(logging, logLevel), format="%(levelname)s:%(module)s:%(lineno)d:%(message)s") - d = tqdm.__doc__ - if sys.version_info >= (3, 13): - # Python 3.13+ automatically dedents docstrings - d = textwrap.indent(d, " ") - d += CLI_EXTRA_DOC + # py<3.13 doesn't dedent docstrings + d = (tqdm.__doc__ if sys.version_info < (3, 13) + else indent(tqdm.__doc__, " ")) + CLI_EXTRA_DOC opt_types = dict(RE_OPTS.findall(d)) # opt_types['delim'] = 'chr' From a3f787594a17ef2e7c1bbe7bd4081d7ca05c9a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 8 Jul 2024 17:26:13 +0200 Subject: [PATCH 3/3] Avoid Python 3.13+ RuntimeWarning: coroutine method 'aclose' of 'acount' was never awaited See https://github.com/python/cpython/issues/117536#issuecomment-2036883124 --- tests/tests_asyncio.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/tests_asyncio.py b/tests/tests_asyncio.py index bdef569f..250e6585 100644 --- a/tests/tests_asyncio.py +++ b/tests/tests_asyncio.py @@ -48,10 +48,14 @@ async def test_generators(capsys): _, err = capsys.readouterr() assert '9it' in err - with tqdm(acount(), desc="async_counter") as pbar: - async for i in pbar: - if i >= 8: - break + acounter = acount() + try: + with tqdm(acounter, desc="async_counter") as pbar: + async for i in pbar: + if i >= 8: + break + finally: + await acounter.aclose() _, err = capsys.readouterr() assert '9it' in err