forked from VimPlug/jedi
Implement the type builtin better and with a lot more tests.
This commit is contained in:
@@ -65,6 +65,9 @@ class GeneratorMixin(object):
|
|||||||
def py__bool__(self):
|
def py__bool__(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def py__class__(self, evaluator):
|
||||||
|
return compiled.generator_obj.py__class__(evaluator)
|
||||||
|
|
||||||
|
|
||||||
class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)):
|
class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)):
|
||||||
"""Handling of `yield` functions."""
|
"""Handling of `yield` functions."""
|
||||||
@@ -160,6 +163,9 @@ class ArrayMixin(object):
|
|||||||
def py__bool__(self):
|
def py__bool__(self):
|
||||||
return None # We don't know the length, because of appends.
|
return None # We don't know the length, because of appends.
|
||||||
|
|
||||||
|
def py__class__(self, evaluator):
|
||||||
|
return compiled.builtin.get_by_name(self.type)
|
||||||
|
|
||||||
|
|
||||||
class ListComprehension(Comprehension, ArrayMixin):
|
class ListComprehension(Comprehension, ArrayMixin):
|
||||||
type = 'list'
|
type = 'list'
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ def builtins_getattr(evaluator, objects, names, defaults=None):
|
|||||||
@argument_clinic('object[, bases, dict], /')
|
@argument_clinic('object[, bases, dict], /')
|
||||||
def builtins_type(evaluator, objects, bases, dicts):
|
def builtins_type(evaluator, objects, bases, dicts):
|
||||||
if bases or dicts:
|
if bases or dicts:
|
||||||
# metaclass... maybe someday...
|
# It's a type creation... maybe someday...
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
return [o.base for o in objects if isinstance(o, er.Instance)]
|
return [o.py__class__(evaluator) for o in objects]
|
||||||
|
|
||||||
|
|
||||||
class SuperInstance(er.Instance):
|
class SuperInstance(er.Instance):
|
||||||
|
|||||||
@@ -35,6 +35,25 @@ next(open(''))
|
|||||||
#? ['__itemsize__']
|
#? ['__itemsize__']
|
||||||
tuple.__itemsize__
|
tuple.__itemsize__
|
||||||
|
|
||||||
|
# type
|
||||||
|
|
||||||
|
#? int
|
||||||
|
type(1)
|
||||||
|
#? int
|
||||||
|
type(int())
|
||||||
|
#? type
|
||||||
|
type(int)
|
||||||
|
#? type
|
||||||
|
type(type)
|
||||||
|
#? list
|
||||||
|
type([])
|
||||||
|
|
||||||
|
def x():
|
||||||
|
yield 1
|
||||||
|
generator = type(x())
|
||||||
|
#? generator
|
||||||
|
type(x for x in [])
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# re
|
# re
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user