Skip to content

Commit a530f7b

Browse files
committed
refactoring
1 parent 54b8508 commit a530f7b

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

refinery/units/meta/pop.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,42 +95,44 @@ def __init__(
9595
if not names:
9696
names = _MERGE_META,
9797
super().__init__(names=[_popcount(n) for n in names])
98-
self._invisible = None
99-
self._remaining = False
98+
self._tos = None
99+
self._eof = True
100100

101101
def process(self, data):
102102
return data
103103

104104
def finish(self) -> Iterable[Chunk]:
105-
if self._remaining:
105+
eof = self._eof
106+
self._tos = None
107+
self._eof = True
108+
if not eof:
106109
msg = 'Not all variables could be assigned.'
107110
if not self.leniency:
108111
raise ValueError(F'{msg} Increase leniency to downgrade this failure to a warning.')
109112
self.log_warn(msg)
110-
self._invisible = None
111-
self._remaining = False
112113
yield from ()
113114

114115
def filter(self, chunks: Iterable[Chunk]):
115-
invisible = self._invisible
116116
variables = {}
117117
remaining: Iterator[_popcount] = iter(self.args.names)
118118

119-
all_invisible = True
120-
it = iter(chunks)
121119
pop = next(remaining).reset()
120+
tos = self._tos
121+
all_invisible = True
122122
all_variables_assigned = False
123123
path = None
124124
view = None
125125

126+
it = iter(chunks)
127+
126128
for chunk in it:
127129
if (path is None):
128130
path = tuple(chunk.path)
129131
if not chunk.visible:
130132
self.log_debug('buffering invisible chunk')
131-
if invisible is not None:
132-
yield invisible
133-
invisible = chunk
133+
if tos is not None:
134+
yield tos
135+
tos = chunk
134136
continue
135137
else:
136138
all_invisible = False
@@ -141,9 +143,9 @@ def filter(self, chunks: Iterable[Chunk]):
141143
pop = next(remaining).reset()
142144
except StopIteration:
143145
all_variables_assigned = True
144-
if invisible is not None:
145-
yield invisible
146-
invisible = chunk
146+
if tos is not None:
147+
yield tos
148+
tos = chunk
147149
break
148150

149151
if not all_variables_assigned and pop.done:
@@ -154,20 +156,20 @@ def filter(self, chunks: Iterable[Chunk]):
154156

155157
if not all_variables_assigned:
156158
if all_invisible and path and not any(path):
157-
self._invisible = invisible
158-
self._remaining = True
159+
self._tos = tos
160+
self._eof = False
159161
return
160162
else:
161-
self._remaining = False
163+
self._eof = True
162164

163165
nesting = self.args.nesting
164166

165-
if invisible is not None:
166-
if path and view and invisible.path != path:
167-
invisible = invisible.copy()
168-
invisible.path[:] = path
169-
invisible.view[:] = view
170-
it = chain([invisible], it)
167+
if tos is not None:
168+
if path and view and tos.path != path:
169+
tos = tos.copy()
170+
tos.path[:] = path
171+
tos.view[:] = view
172+
it = chain([tos], it)
171173

172174
for chunk in it:
173175
meta = chunk.meta

0 commit comments

Comments
 (0)