Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit f7b497d

Browse files
committed
feature: Make Features a collections.UserList
Signed-off-by: John Andersen <[email protected]>
1 parent bff2838 commit f7b497d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

dffml/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import functools
1111
import contextlib
12+
import collections
1213
import dataclasses
1314
from argparse import ArgumentParser
1415
from typing import Dict, Any, Type, Optional
@@ -122,7 +123,7 @@ def mkarg(field):
122123
if field.type == bool:
123124
arg["action"] = "store_true"
124125
elif inspect.isclass(field.type):
125-
if issubclass(field.type, list):
126+
if issubclass(field.type, (list, collections.UserList)):
126127
arg["nargs"] = "+"
127128
if not hasattr(field.type, "SINGLETON"):
128129
raise AttributeError(

dffml/feature/feature.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import abc
88
import pydoc
99
import asyncio
10+
import collections
1011
from contextlib import AsyncExitStack
1112
from typing import List, Dict, Type, Any
1213

@@ -219,7 +220,7 @@ def length(self) -> int:
219220
return DefinedFeature(name=name, dtype=dtype, length=length)
220221

221222

222-
class Features(list):
223+
class Features(collections.UserList):
223224

224225
TIMEOUT: int = 60 * 2
225226
SINGLETON = Feature
@@ -232,10 +233,10 @@ def __init__(self, *args: Feature, timeout: int = None) -> None:
232233
self.timeout = timeout if not timeout is None else self.TIMEOUT
233234

234235
def names(self) -> List[str]:
235-
return list(({feature.NAME: True for feature in self}).keys())
236+
return list(({feature.NAME: True for feature in self.data}).keys())
236237

237238
def export(self):
238-
return {feature.NAME: feature.export() for feature in self}
239+
return {feature.NAME: feature.export() for feature in self.data}
239240

240241
@classmethod
241242
def _fromdict(cls, **kwargs):
@@ -251,7 +252,7 @@ def _fromdict(cls, **kwargs):
251252
async def __aenter__(self):
252253
self._stack = AsyncExitStack()
253254
await self._stack.__aenter__()
254-
for item in self:
255+
for item in self.data:
255256
await self._stack.enter_async_context(item)
256257
return self
257258

0 commit comments

Comments
 (0)