def add_builtin_objects()

in src/Analysis/Ast/Impl/scrape_module.py [0:0]


def add_builtin_objects(state):
    Signature.KNOWN_RESTYPES.update({
        "__Type__.__call__": "cls()",
        "__Property__.__delete__": "None",
        "__Float__.__getformat__": "''",
        "__Bytes__.__getitem__": "__T__()",
        "__Unicode__.__getitem__": "__T__()",
        "__Type__.__instancecheck__": "False",
        "__Tuple__.__iter__": "__TupleIterator__()",
        "__List__.__iter__": "__ListIterator__()",
        "__Dict__.__iter__": "__DictKeys__()",
        "__Set__.__iter__": "__SetIterator__()",
        "__FrozenSet__.__iter__": "__SetIterator__()",
        "__Bytes__.__iter__": "__BytesIterator__()",
        "__Unicode__.__iter__": "__UnicodeIterator__()",
        "__BytesIterator__.__next__": "0",
        "__UnicodeIterator__.__next__": "__Unicode__()",
        "__Type__.__prepare__": "None",
        "__List__.__reversed__": "__ListIterator__()",
        "__Float__.__setformat__": "None",
        "__Type__.__subclasses__": "(cls,)",
        "__truediv__": "__Float__()",
        "__Type__.__subclasscheck__": "False",
        "__subclasshook__": "False",
        "all": "False",
        "any": "False",
        "ascii": "''",
        "__Set__.add": "None",
        "__List__.append": "None",
        "__Float__.as_integer_ratio": "(0, 0)",
        "bin": "''",
        "__Int__.bit_length": "0",
        "callable": "False",
        "capitalize": "__T__()",
        "casefold": "__T__()",
        "center": "__T__()",
        "chr": "''",
        "clear": "None",
        "__Generator__.close": "None",
        "conjugate": "__Complex__()",
        "copy": "__T__()",
        "count": "0",
        "__Bytes__.decode": "''",
        "__Property__.deleter": "func",
        "__Set__.difference": "__T__()",
        "__FrozenSet__.difference": "__T__()",
        "__Set__.difference_update": "None",
        "__Set__.discard": "None",
        "divmod": "(0, 0)",
        "__Bytes__.encode": "b''",
        "__Unicode__.encode": "b''",
        "endswith": "False",
        "expandtabs": "__T__()",
        "__List__.extend": "None",
        "find": "0",
        "__Unicode__.format": "__T__()",
        "__Unicode__.format_map": "__T__()",
        "__Bool__.from_bytes": "False",
        "__Int__.from_bytes": "0",
        "__Long__.from_bytes": "__Long__()",
        "__Float__.fromhex": "0.0",
        "__Bytes__.fromhex": "b''",
        "__Dict__.fromkeys": "{}",
        "__Dict__.get": "self[0]",
        "__Property__.getter": "func",
        "format": "''",
        "globals": "__Dict__()",
        "hasattr": "False",
        "hash": "0",
        "hex": "''",
        "id": "0",
        "index": "0",
        "input": "''",
        "__List__.insert": "None",
        "__Set__.intersection": "__T__()",
        "__FrozenSet__.intersection": "__T__()",
        "__Set__.intersection_update": "None",
        "isalnum": "False",
        "isalpha": "False",
        "isdecimal": "False",
        "isdigit": "False",
        "islower": "False",
        "isidentifier": "False",
        "isnumeric": "False",
        "isprintable": "False",
        "isspace": "False",
        "istitle": "False",
        "isupper": "False",
        "__Float__.is_integer": "False",
        "__Set__.isdisjoint": "False",
        "__FrozenSet__.isdisjoint": "False",
        "__DictKeys__.isdisjoint": "False",
        "__DictItems__.isdisjoint": "False",
        "__Set__.issubset": "False",
        "__FrozenSet__.issubset": "False",
        "__Set__.issuperset": "False",
        "__FrozenSet__.issuperset": "False",
        "__Dict__.items": "__DictItems__()",
        "__Bytes__.join": "b''",
        "__Unicode__.join": "''",
        "__Dict__.keys": "__DictKeys__()",
        "len": "0",
        "locals": "__Dict__()",
        "lower": "__T__()",
        "ljust": "__T__()",
        "lstrip": "__T__()",
        "__Bytes__.maketrans": "b''",
        "__Unicode__.maketrans": "{}",
        "__Type__.mro": "[__Type__()]",
        "oct": "''",
        "partition": "(__T__(), __T__(), __T__())",
        "__List__.pop": "self[0]",
        "__Dict__.pop": "self.keys()[0]",
        "__Set__.pop": "Any",
        "__Dict__.popitem": "self.items()[0]",
        "remove": "None",
        "replace": "__T__()",
        "repr": "''",
        "rfind": "0",
        "__List__.reverse": "None",
        "rindex": "0",
        "rjust": "__T__()",
        "round": "0.0",
        "rpartition": "(__T__(), __T__(), __T__())",
        "rsplit": "[__T__()]",
        "rstrip": "__T__()",
        "__Generator__.send": "self.__next__()",
        "__Dict__.setdefault": "self[0]",
        "__Property__.setter": "func",
        "__List__.sort": "None",
        "sorted": "__List__()",
        "split": "[__T__()]",
        "splitlines": "[self()]",
        "startswith": "False",
        "strip": "__T__()",
        "swapcase": "__T__()",
        "__Set__.symmetric_difference": "__T__()",
        "__FrozenSet__.symmetric_difference": "__T__()",
        "__Set__.symmetric_difference_update": "None",
        "__Bytes__.translate": "__T__()",
        "__Unicode__.translate": "__T__()",
        "__Generator__.throw": "None",
        "title": "__T__()",
        "to_bytes": "b''",
        "__Set__.union": "__T__()",
        "__FrozenSet__.union": "__T__()",
        "__Dict__.update": "None",
        "__Set__.update": "None",
        "upper": "__T__()",
        "__Dict__.values": "__DictValues__()",
        "zfill": "__T__()",
    })

    Signature.KNOWN_ARGSPECS.update({
        "__Type__.__call__": "(cls, *args, **kwargs)",
        "__Int__.__ceil__": "(self)",
        "__Int__.__floor__": "(self)",
        "__Float__.__getformat__": "(typestr)",
        "__Dict__.__getitem__": "(self, key)",
        "__Type__.__instancecheck__": "(self, instance)",
        "__Bool__.__init__": "(self, x)",
        "__Int__.__init__": "(self, x=0)",
        "__List__.__init__": "(self, iterable)",
        "__Tuple__.__init__": "(self, iterable)",
        "__Type__.__prepare__": "(cls, name, bases, **kwds)",
        "__Int__.__round__": "(self, ndigits=0)",
        "__Float__.__round__": "(self, ndigits=0)",
        "__List__.__reversed__": "(self)",
        "__Float__.__setformat__": "(typestr, fmt)",
        "__Dict__.__setitem__": "(self, key, value)",
        "__Set__.add": "(self, value)",
        "__List__.append": "(self, value)",
        "__Float__.as_integer_ratio": "(self)",
        "__Int__.bit_length": "(self)",
        "capitalize": "(self)",
        "casefold": "(self)",
        "__Bytes__.center": "(self, width, fillbyte=b' ')",
        "__Unicode__.center": "(self, width, fillchar=' ')",
        "clear": "(self)",
        "__Generator__.close": "(self)",
        "conjugate": "(self)",
        "copy": "(self)",
        "count": "(self, x)",
        "__Bytes__.count": "(self, sub, start=0, end=-1)",
        "__Unicode__.count": "(self, sub, start=0, end=-1)",
        "__Bytes__.decode": "(self, encoding='utf-8', errors='strict')",
        "__Property__.deleter": "(self, func)",
        "__Set__.difference": "(self, other)",
        "__FrozenSet__.difference": "(self, other)",
        "__Set__.difference_update": "(self, *others)",
        "__Set__.discard": "(self, elem)",
        "__Unicode__.encode": "(self, encoding='utf-8', errors='strict')",
        "endswith": "(self, suffix, start=0, end=-1)",
        "expandtabs": "(self, tabsize=8)",
        "__List__.extend": "(self, iterable)",
        "find": "(self, sub, start=0, end=-1)",
        "__Unicode__.format": "(self, *args, **kwargs)",
        "__Unicode__.format_map": "(self, mapping)",
        "__Bool__.from_bytes": "(bytes, byteorder, *, signed=False)",
        "__Int__.from_bytes": "(bytes, byteorder, *, signed=False)",
        "__Float__.fromhex": "(string)",
        "__Dict__.get": "(self, key, d=None)",
        "__Property__.getter": "(self, func)",
        "hex": "(self)",
        "__List__.insert": "(self, index, value)",
        "index": "(self, v)",
        "__Bytes__.index": "(self, sub, start=0, end=-1)",
        "__Unicode__.index": "(self, sub, start=0, end=-1)",
        "__Set__.intersection": "(self, other)",
        "__FrozenSet__.intersection": "(self, other)",
        "__Set__.intersection_update": "(self, *others)",
        "isalnum": "(self)",
        "isalpha": "(self)",
        "isdecimal": "(self)",
        "isdigit": "(self)",
        "isidentifier": "(self)",
        "islower": "(self)",
        "isnumeric": "(self)",
        "isprintable": "(self)",
        "isspace": "(self)",
        "istitle": "(self)",
        "isupper": "(self)",
        "__Float__.is_integer": "(self)",
        "__Set__.isdisjoint": "(self, other)",
        "__FrozenSet__.isdisjoint": "(self, other)",
        "__DictKeys__.isdisjoint": "(self, other)",
        "__DictItems__.isdisjoint": "(self, other)",
        "__Set__.issubset": "(self, other)",
        "__FrozenSet__.issubset": "(self, other)",
        "__Set__.issuperset": "(self, other)",
        "__FrozenSet__.issuperset": "(self, other)",
        "__Dict__.items": "(self)",
        "__Bytes__.join": "(self, iterable)",
        "__Unicode__.join": "(self, iterable)",
        "__Dict__.keys": "(self)",
        "lower": "(self)",
        "__Bytes__.ljust": "(self, width, fillbyte=b' ')",
        "__Unicode__.ljust": "(self, width, fillchar=' ')",
        "lstrip": "(self, chars)",
        "__Bytes__.maketrans": "(from_, to)",
        "__Unicode__.maketrans": "(x, y, z)",
        "__Type__.mro": "(cls)",
        "__Bytes__.partition": "(self, sep)",
        "__Unicode__.partition": "(self, sep)",
        "__List__.pop": "(self, index=-1)",
        "__Dict__.pop": "(self, k, d=None)",
        "__Set__.pop": "(self)",
        "__Dict__.popitem": "(self, k, d=None)",
        "__List__.remove": "(self, value)",
        "__Set__.remove": "(self, elem)",
        "replace": "(self, old, new, count=-1)",
        "__List__.reverse": "(self)",
        "rfind": "(self, sub, start=0, end=-1)",
        "rindex": "(self, sub, start=0, end=-1)",
        "__Bytes__.rjust": "(self, width, fillbyte=b' ')",
        "__Unicode__.rjust": "(self, width, fillchar=' ')",
        "__Bytes__.rpartition": "(self, sep)",
        "__Unicode__.rpartition": "(self, sep)",
        "rsplit": "(self, sep=None, maxsplit=-1)",
        "rstrip": "(self, chars=None)",
        "__Generator__.send": "(self, value)",
        "__Dict__.setdefault": "(self, k, d)",
        "__Property__.setter": "(self, func)",
        "__List__.sort": "(self)",
        "split": "(self, sep=None, maxsplit=-1)",
        "splitlines": "(self, keepends=False)",
        "strip": "(self, chars=None)",
        "startswith": "(self, prefix, start=0, end=-1)",
        "swapcase": "(self)",
        "__Set__.symmetric_difference": "(self, other)",
        "__FrozenSet__.symmetric_difference": "(self, other)",
        "__Set__.symmetric_difference_update": "(self, *others)",
        "__Generator__.throw": "(self, type, value=None, traceback=None)",
        "title": "(self)",
        "__Int__.to_bytes": "(bytes, byteorder, *, signed=False)",
        "__Bytes__.translate": "(self, table, delete=b'')",
        "__Unicode__.translate": "(self, table)",
        "__Set__.union": "(self, *others)",
        "__FrozenSet__.union": "(self, *others)",
        "__Dict__.update": "(self, d)",
        "__Set__.update": "(self, *others)",
        "upper": "(self)",
        "__Dict__.values": "(self)",
        "zfill": "(self, width)",
    })

    if sys.version[0] == '2':
        Signature.KNOWN_RESTYPES.update({
            "__BytesIterator__.__next__": None,
            "__BytesIterator__.next": "b''",
            "__UnicodeIterator__.__next__": None,
            "__UnicodeIterator__.next": "u''",
            "__Generator__.send": "self.next()",
            "__Function__.func_closure": "()",
            "__Function__.func_doc": "b''",
            "__Function__.func_name": "b''",
            "input": None,
            "raw_input": "b''",
        })

        Signature.KNOWN_ARGSPECS.update({
            "__BytesIterator__.next": "(self)",
            "__UnicodeIterator__.next": "(self)",
        })

    already_added = set()

    def add_simple(name, doc, *members):
        mi = MemberInfo(name, MemberInfo.NO_VALUE)
        mi.documentation = doc
        mi.need_imports = (state.module_name,)
        mi.members.extend(members)
        state.members.append(mi)

    def add_literal(name, literal):
        state.members.append(MemberInfo(name, None, literal=literal))

    def add_type(alias, type_obj):
        if type_obj.__name__ in already_added:
            add_literal(alias, type_obj.__name__)
            return
        already_added.add(type_obj.__name__)
        mi = MemberInfo(type_obj.__name__, type_obj, module=builtins.__name__, alias=alias)
        state.members.append(mi)
        state.members.append(MemberInfo(alias, None, literal=mi.name))

    # We don't need these anymore, as Unknown and None are specialized in the analysis.
    #add_simple('__Unknown__', '<unknown>', MemberInfo("__name__", None, literal='"<unknown>"'))
    #add_simple('__NoneType__', 'the type of the None object', MemberInfo.NO_VALUE)

    # NoneType and None are explicitly defined to avoid parser errors
    # because of None being a keyword.
    #add_literal('NoneType', '__NoneType__')
    #add_literal('None', '__NoneType__()')

    add_type('__Object__', object)
    add_type('__Type__', type)
    
    add_type('__Int__', int)
    if type(bool()) is int:
        add_literal('__Bool__', '__Int__')
    else:
        add_type('__Bool__', bool)

    try:
        long
    except NameError:
        add_literal('__Long__', '__Int__')
    else:
        add_type('__Long__', long)

    add_type("__Float__", float)
    add_type("__Complex__", complex)

    add_type("__Tuple__", tuple)
    add_type("__List__", list)
    add_type("__Dict__", dict)
    add_type("__Set__", set)
    add_type("__FrozenSet__", frozenset)

    if bytes is not str:
        add_type("__Bytes__", bytes)
        add_type("__BytesIterator__", type(iter(bytes())))
        add_type("__Unicode__", str)
        add_type("__UnicodeIterator__", type(iter(str())))
        add_literal("__Str__", "__Unicode__")
        add_literal("__StrIterator__", "__UnicodeIterator__")

    else:
        add_type("__Bytes__", str)
        add_type("__BytesIterator__", type(iter(str())))
        add_type("__Unicode__", unicode)
        add_type("__UnicodeIterator__", type(iter(unicode())))
        add_literal("__Str__", "__Bytes__")
        add_literal("__StrIterator__", "__BytesIterator__")

    add_type("__Module__", type(inspect))
    add_type("__Function__", type(add_simple))

    add_type("__BuiltinMethodDescriptor__", type(object.__hash__))
    add_type("__BuiltinFunction__", type(abs))
    add_type("__Generator__", type((_ for _ in [])))
    add_type("__Property__", property)
    add_type("__ClassMethod__", classmethod)
    add_type("__StaticMethod__", staticmethod)
    add_type("__Ellipsis__", type(Ellipsis))
    add_type("__TupleIterator__", type(iter(())))
    add_type("__ListIterator__", type(iter([])))
    add_type("__DictKeys__", type({}.keys()))
    add_type("__DictValues__", type({}.values()))
    add_type("__DictItems__", type({}.items()))
    add_type("__SetIterator__", type(iter(set())))
    add_type("__CallableIterator__", type(iter((lambda: None), None)))

    # Also write out the builtin module names here so that we cache them
    try:
        builtin_module_names = sys.builtin_module_names
    except AttributeError:
        pass
    else:
        add_literal('__builtin_module_names__', '"' + ','.join(builtin_module_names) + '"')