1
0
forked from VimPlug/jedi

Implement random.choice

This commit is contained in:
Dave Halter
2018-09-03 01:35:30 +02:00
parent 5302032b63
commit 3351b06603
2 changed files with 16 additions and 1 deletions

View File

@@ -31,7 +31,6 @@ class BaseContextSet(object):
Used to work with an iterable of set. Used to work with an iterable of set.
""" """
aggregated = set() aggregated = set()
sets = list(sets)
for set_ in sets: for set_ in sets:
if isinstance(set_, BaseContextSet): if isinstance(set_, BaseContextSet):
aggregated |= set_._set aggregated |= set_._set

View File

@@ -344,6 +344,15 @@ def _return_first_param(evaluator, firsts):
return firsts return firsts
@argument_clinic('seq')
def _random_choice(evaluator, sequences):
return ContextSet.from_sets(
lazy_context.infer()
for sequence in sequences
for lazy_context in sequence.py__iter__()
)
_implemented = { _implemented = {
'builtins': { 'builtins': {
'getattr': builtins_getattr, 'getattr': builtins_getattr,
@@ -365,6 +374,13 @@ _implemented = {
}, },
'functools': { 'functools': {
'partial': functools_partial, 'partial': functools_partial,
'wraps': _return_first_param,
},
'_weakref': {
'proxy': _return_first_param,
},
'random': {
'choice': _random_choice,
}, },
'abc': { 'abc': {
# Not sure if this is necessary, but it's used a lot in typeshed and # Not sure if this is necessary, but it's used a lot in typeshed and