Skip to content

Commit

Permalink
Convert uniq to generator
Browse files Browse the repository at this point in the history
  • Loading branch information
davesque committed Jun 27, 2019
1 parent 2403d26 commit 052e8c6
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions bin/vyper
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import os
import sys
from typing import (
Any,
Generator,
Iterable,
List,
Set,
TypeVar,
)
Expand Down Expand Up @@ -87,21 +87,18 @@ elif not args.debug:
T = TypeVar('T')


def uniq(seq: Iterable[T]) -> List[T]:
def uniq(seq: Iterable[T]) -> Generator[T, None, None]:
"""
Returns unique items in ``seq`` in order.
Yield unique items in ``seq`` in order.
"""
seen: Set[T] = set()
result = []

for x in seq:
if x in seen:
continue

seen.add(x)
result.append(x)

return result
yield x


def exc_handler(contract_name: ContractName, exception: Exception) -> None:
Expand Down Expand Up @@ -173,7 +170,7 @@ if __name__ == '__main__':
'ast': 'ast_dict'
}
formats = []
orig_args = uniq(args.format.split(','))
orig_args = tuple(uniq(args.format.split(',')))

for f in orig_args:
formats.append(translate_map.get(f, f))
Expand Down

0 comments on commit 052e8c6

Please sign in to comment.