Merge pull request #2928 from RustPython/upd-types

Update types.py to CPython 3.8
This commit is contained in:
Jeong YunWon
2021-08-22 15:18:52 +09:00
committed by GitHub

19
Lib/types.py vendored
View File

@@ -15,6 +15,13 @@ CodeType = type(_f.__code__)
MappingProxyType = type(type.__dict__)
SimpleNamespace = type(sys.implementation)
def _cell_factory():
a = 1
def f():
nonlocal a
return f.__closure__[0]
CellType = type(_cell_factory())
def _g():
yield 1
GeneratorType = type(_g())
@@ -55,7 +62,7 @@ except TypeError:
GetSetDescriptorType = type(FunctionType.__code__)
MemberDescriptorType = type(FunctionType.__globals__)
del sys, _f, _g, _C # Not for export
del sys, _f, _g, _C, _c, _ag # Not for export
# Provide a PEP 3115 compliant mechanism for class creation
@@ -256,14 +263,8 @@ def coroutine(func):
if co_flags & 0x20:
# TODO: Implement this in C.
co = func.__code__
func.__code__ = CodeType(
co.co_argcount, co.co_kwonlyargcount, co.co_nlocals,
co.co_stacksize,
co.co_flags | 0x100, # 0x100 == CO_ITERABLE_COROUTINE
co.co_code,
co.co_consts, co.co_names, co.co_varnames, co.co_filename,
co.co_name, co.co_firstlineno, co.co_lnotab, co.co_freevars,
co.co_cellvars)
# 0x100 == CO_ITERABLE_COROUTINE
func.__code__ = co.replace(co_flags=co.co_flags | 0x100)
return func
# The following code is primarily to support functions that