!18 more.py: document ilen

From: @zhang-liang-pengkun 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
This commit is contained in:
openeuler-ci-bot 2023-11-24 07:44:05 +00:00 committed by Gitee
commit bc1c5c3bbc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,29 @@
From fc39d84358199cd0fc7a33e9179244a4987e36c7 Mon Sep 17 00:00:00 2001
From: Ben Mintz <bmintz@protonmail.com>
Date: Mon, 7 May 2018 03:29:41 -0500
Subject: [PATCH] more.py: document ilen
I found the implementation of ilen to be confusing, so I documented it.
---
more_itertools/more.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/more_itertools/more.py b/more_itertools/more.py
index 6de5b03..a5fd960 100644
--- a/more_itertools/more.py
+++ b/more_itertools/more.py
@@ -409,7 +409,11 @@ def ilen(iterable):
This consumes the iterable, so handle with care.
"""
+ # maxlen=1 only stores the last item in the deque
d = deque(enumerate(iterable, 1), maxlen=1)
+ # since we started enumerate at 1,
+ # the first item of the last pair will be the length of the iterable
+ # (assuming there were items)
return d[0][0] if d else 0
--
2.39.0.windows.2

View File

@ -8,6 +8,7 @@ Source0: https://pypi.io/packages/source/m/more-itertools/more-itertools-
BuildArch: noarch
Patch0000: python37.patch
Patch0001: 0001-fix-for-python-3.7-deprecation-warning-about-importi.patch
Patch0002: 0002-more.py-document-ilen.patch
%description
This is a python library for efficient use of itertools utility, which also \
@ -62,6 +63,9 @@ See https://pythonhosted.org/more-itertools/index.html for more information.
%{python3_sitelib}/more_itertools-%{version}-py%{python3_version}.egg-info
%changelog
* Fri Nov 24 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> -
- more.py: document ilen
* Thu Nov 16 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 4.1.0-6
- fix for python 3.7 deprecation warning about importing certain types from collections vs collections.abc