mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
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):
|
||||
return True
|
||||
|
||||
def py__class__(self, evaluator):
|
||||
return compiled.generator_obj.py__class__(evaluator)
|
||||
|
||||
|
||||
class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)):
|
||||
"""Handling of `yield` functions."""
|
||||
@@ -160,6 +163,9 @@ class ArrayMixin(object):
|
||||
def py__bool__(self):
|
||||
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):
|
||||
type = 'list'
|
||||
|
||||
@@ -114,10 +114,10 @@ def builtins_getattr(evaluator, objects, names, defaults=None):
|
||||
@argument_clinic('object[, bases, dict], /')
|
||||
def builtins_type(evaluator, objects, bases, dicts):
|
||||
if bases or dicts:
|
||||
# metaclass... maybe someday...
|
||||
# It's a type creation... maybe someday...
|
||||
return []
|
||||
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):
|
||||
|
||||
@@ -35,6 +35,25 @@ next(open(''))
|
||||
#? ['__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
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user