-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md.tpl
More file actions
150 lines (110 loc) · 4.31 KB
/
README.md.tpl
File metadata and controls
150 lines (110 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# python-repeatable-iterable
[![PyPI-version-badge]][PyPI-package-page]
[![Downloads-badge]][PyPIStats-package-page]
[![Code-style:black:badge]][Black-github.xm233.cn]
[![Imports:isort:badge]][Isort-GitHub.io]
[![Typecheck:mypy:badge]][Typecheck-mypy-lang.org]
[![Linting:pylint:badge]][Pylint-github.xm233.cn]
[![CodeFactor-badge]][CodeFactor-package-page]
[![CodeClimateMaintainability-badge]][CodeClimateM13y-package-page]
[![Codacy-badge]][Codacy-package-page]
![GitHub-top-language-badge]
![GitHub-license-badge]
![PyPI-python-version-badge]
![GitHub-code-size-in-bytes-badge]
| **A new type RepeatableIterable for Python** |
|:--------------------------------------------:|
| **and a way to obtain one instance** |
Since in Python an Iterator is an Iterable
and that you cannot iterate multiple times on an iterator,
you may encounter WTF bugs, even with type checking.
This package provides possible solutions to this problem.
See here for a discussion on this problem:
<https://stackoverflow.com/questions/63104689>
(/what-is-the-pythonic-way-to-represent-an-iterable
-that-can-be-iterated-over-mult).
Before:
```python3
def foo(iterable: Iterable):
for that in iterable:
bar(that)
for that in iterable:
# possible bug
baz(that)
foo(something)
```
After solution 1:
```python3
from python_repeatable_iterable import RepeatableIterable
def foo(iterable: RepeatableIterable[object]):
for that in iterable:
bar(that)
for that in iterable:
baz(that)
something_else = RepeatableIterable(something)
foo(something_else)
```
After solution 2:
```python3
from python_repeatable_iterable import RepeatableIterable
def foo(iterable: Iterable):
iterable = RepeatableIterable(iterable)
for that in iterable:
bar(that)
for that in iterable:
baz(that)
foo(something)
```
If you develop something where you have no control on
what another dev might give you as input,
you have 2 possibilities:
- hope for the best ;),
- or harden your code to have less support work to do :).
This applies if you dev something that is:
- closed source or open source,
- available to everyone on the Internet,
available only to customers or colleagues
that you may personally know or not.
Solution 2 above is a nice solution
with a reasonable performance cost :).
[PyPI-version-badge]: https://img.shields.io/pypi/v/\
python-repeatable-iterable.svg
[PyPI-package-page]: https://pypi.org/project/\
python-repeatable-iterable/
[Downloads-badge]: https://img.shields.io/pypi/dm/\
python-repeatable-iterable
[PyPIStats-package-page]: https://pypistats.org/packages/\
python-repeatable-iterable
[Code-style:black:badge]: https://img.shields.io/badge/\
code%20style-black-000000.svg
[Black-github.xm233.cn]: https://github.com/psf/black
[Imports:isort:badge]: https://img.shields.io/badge/\
%20imports-isort-%231674b1?style=flat&labelColor=ef8336
[Isort-GitHub.io]: https://pycqa.github.io/isort/
[Typecheck:mypy:badge]: https://www.mypy-lang.org/static/\
mypy_badge.svg
[Typecheck-mypy-lang.org]: https://mypy-lang.org/
[Linting:pylint:badge]: https://img.shields.io/badge/\
linting-pylint-yellowgreen
[Pylint-github.xm233.cn]: https://github.com/pylint-dev/pylint
[CodeFactor-badge]: https://www.codefactor.io/repository/github/\
llyaudet/python-repeatable-iterable/badge/main
[CodeFactor-package-page]: https://www.codefactor.io/repository/\
github/llyaudet/python-repeatable-iterable/overview/main
[CodeClimateMaintainability-badge]: https://api.codeclimate.com/v1/\
badges/89044bfd52999e4f07f6/maintainability
[CodeClimateM13y-package-page]: https://codeclimate.com/github/\
LLyaudet/python-repeatable-iterable/maintainability
[Codacy-badge]: https://app.codacy.com/project/badge/Grade/\
1c70116c2d714e3889606519937cb11d
[Codacy-package-page]: https://app.codacy.com/gh/LLyaudet/\
python-repeatable-iterable/dashboard?utm_source=gh\
&utm_medium=referral&utm_content=&utm_campaign=Badge_grade
[GitHub-top-language-badge]: https://img.shields.io/github/\
languages/top/llyaudet/python-repeatable-iterable
[GitHub-license-badge]: https://img.shields.io/github/license/\
llyaudet/python-repeatable-iterable
[PyPI-python-version-badge]: https://img.shields.io/pypi/pyversions/\
python-repeatable-iterable
[GitHub-code-size-in-bytes-badge]: https://img.shields.io/github/\
languages/code-size/llyaudet/python-repeatable-iterable