summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* bpo-38530: Properly extend UnboundLocalError from NameError (GH-25444)Pablo Galindo2021-04-161-1/+2
|
* bpo-38530: Offer suggestions on NameError (GH-25397)Pablo Galindo2021-04-141-2/+63
| | | | | | | | | | | When printing NameError raised by the interpreter, PyErr_Display will offer suggestions of simmilar variable names in the function that the exception was raised from: >>> schwarzschild_black_hole = None >>> schwarschild_black_hole Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'schwarschild_black_hole' is not defined. Did you mean: schwarzschild_black_hole?
* bpo-38530: Offer suggestions on AttributeError (#16856)Pablo Galindo2021-04-142-12/+112
| | | | | | | | | When printing AttributeError, PyErr_Display will offer suggestions of similar attribute names in the object that the exception was raised from: >>> collections.namedtoplo Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: namedtuple?
* bpo-43770: Cleanup type_ready() (GH-25388)Victor Stinner2021-04-131-119/+153
| | | | | | * Rename functions * Only pass type parameter to "add_xxx" functions. * Clarify the role of the type_ready_inherit_as_structs() function. * Move type_dict_set_doc() code to call it in type_ready_fill_dict().
* bpo-43770: Reorder type_ready() (GH-25373)Victor Stinner2021-04-131-48/+56
| | | | | | | Add type_ready_create_dict() sub-function. * Start with type_ready_create_dict(). * Call type_ready_mro() earlier, before type_ready_add_attrs(). * Call type_ready_inherit_special() earlier, in type_ready_inherit().
* bpo-43682: Make staticmethod objects callable (GH-25117)Victor Stinner2021-04-111-1/+8
| | | Static methods (@staticmethod) are now callable as regular functions.
* bpo-43770: Refactor PyType_Ready() function (GH-25336)Victor Stinner2021-04-111-154/+270
| | | | | | * Split PyType_Ready() into sub-functions. * type_ready_mro() now checks if bases are static types earlier. * Check tp_name earlier, in type_ready_checks(). * Add _PyType_IsReady() macro to check if a type is ready.
* bpo-43751: Fix anext() bug where it erroneously returned None (GH-25238)Dennis Sweeney2021-04-111-1/+46
|
* bpo-43753: Add Py_Is() and Py_IsNone() functions (GH-25227)Victor Stinner2021-04-101-0/+27
| | | | | | | Add the Py_Is(x, y) function to test if the 'x' object is the 'y' object, the same as "x is y" in Python. Add also the Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions to test if an object is, respectively, the None singleton, the True singleton or the False singleton.
* bpo-43770: Refactor type_new() function (GH-25325)Victor Stinner2021-04-102-395/+734
| | | | | | | | | | | | * Split type_new() into into many small functions. * Add type_new_ctx structure to pass variables between subfunctions. * Initialize some PyTypeObject and PyHeapTypeObject members earlier in type_new_alloc(). * Rename variables to more specific names. * Add "__weakref__" identifier for type_new_visit_slots(). * Factorize code to convert a method to a classmethod (__init_subclass__ and __class_getitem__). * Add braces to respect PEP 7. * Move variable declarations where the variables are initialized.
* bpo-43682: @staticmethod inherits attributes (GH-25268)Victor Stinner2021-04-091-9/+71
| | | | | | | | | | Static methods (@staticmethod) and class methods (@classmethod) now inherit the method attributes (__module__, __name__, __qualname__, __doc__, __annotations__) and have a new __wrapped__ attribute. Changes: * Add a repr() method to staticmethod and classmethod types. * Add tests on the @classmethod decorator.
* bpo-43770: _PyTypes_Init() inits _PyAnextAwaitable_Type (GH-25266)Victor Stinner2021-04-082-2/+3
| | | | * Rename PyAnextAwaitable_Type to _PyAnextAwaitable_Type. * Expose the type in the internal C API.
* bpo-43770: _PyTypes_Init() inits more static types (GH-25265)Victor Stinner2021-04-071-0/+23
|
* bpo-43770: Sort types in _PyTypes_Init() (GH-25263)Victor Stinner2021-04-071-71/+76
|
* bpo-43683: Handle generator entry in bytecode (GH-25138)Mark Shannon2021-04-061-21/+6
| | | | | | * Handle check for sending None to starting generator and coroutine into bytecode. * Document new bytecode and make it fail gracefully if mis-compiled.
* bpo-43688: Support the limited C API in debug mode (GH-25131)Victor Stinner2021-04-021-0/+17
| | | | | | | | | | | | | The limited C API is now supported if Python is built in debug mode (if the Py_DEBUG macro is defined). In the limited C API, the Py_INCREF() and Py_DECREF() functions are now implemented as opaque function calls, rather than accessing directly the PyObject.ob_refcnt member, if Python is built in debug mode and the Py_LIMITED_API macro targets Python 3.10 or newer. It became possible to support the limited C API in debug mode because the PyObject structure is the same in release and debug mode since Python 3.8 (see bpo-36465). The limited C API is still not supported in the --with-trace-refs special build (Py_TRACE_REFS macro).
* bpo-43687: Py_Initialize() creates singletons earlier (GH-25147)Victor Stinner2021-04-024-36/+48
| | | | | Reorganize pycore_interp_init() to initialize singletons before the the first PyType_Ready() call. Fix an issue when Python is configured using --without-doc-strings.
* bpo-27129: Use instruction offsets, not byte offsets, in bytecode and ↵Mark Shannon2021-04-013-13/+22
| | | | | | | internally. (GH-25069) * Use instruction offset, rather than bytecode offset. Streamlines interpreter dispatch a bit, and removes most EXTENDED_ARGs for jumps. * Change some uses of PyCode_Addr2Line to PyFrame_GetLineNumber
* When printing stats, move radix tree info to its own section. (GH-25125)Tim Peters2021-04-011-9/+14
| | | | | | When printing stats, move radix tree info to its own section. Restore that the breakdown of bytes in arenas exactly accounts for the total of arena bytes allocated. Add an assert so that invariant doesn't break again.
* bpo-43179: Generalise alignment for optimised string routines (GH-24624)Jessica Clarke2021-03-314-30/+14
| | | | | | | | | | | | | | | | | | | | | | | | | * Remove m68k-specific hack from ascii_decode On m68k, alignments of primitives is more relaxed, with 4-byte and 8-byte types only requiring 2-byte alignment, thus using sizeof(size_t) does not work. Instead, use the portable alternative. Note that this is a minimal fix that only relaxes the assertion and the condition for when to use the optimised version remains overly strict. Such issues will be fixed tree-wide in the next commit. NB: In C11 we could use _Alignof(size_t) instead, but for compatibility we use autoconf. * Optimise string routines for architectures with non-natural alignment C only requires that sizeof(x) is a multiple of alignof(x), not that the two are equal. Thus anywhere where we optimise based on alignment we should be using alignof(x) not sizeof(x). This is more annoying than it would be in C11 where we could just use _Alignof(x) (and alignof(x) in C++11), but since we still require only C99 we must plumb the information all the way from autoconf through the various typedefs and defines.
* bpo-37448: Use radix tree for pymalloc address_in_range(). (GH-14474)Neil Schemenauer2021-03-301-5/+336
| | | | | | | | The radix tree approach is a relatively simple and memory sanitary alternative to the old (slightly) unsanitary address_in_range(). To disable the radix tree map, set a preprocessor flag as follows: -DWITH_PYMALLOC_RADIX_TREE=0. Co-authored-by: Tim Peters <tim.peters@gmail.com>
* bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)Inada Naoki2021-03-291-0/+9
| | | | | | | | | | | See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
* bpo-43636: Validate the version tag in _PyType_Lookup (GH-25032)Pablo Galindo2021-03-271-1/+3
|
* bpo-43198: Revert 3dd2157 that removed freeslot tracking. (#25010)Raymond Hettinger2021-03-241-1/+15
|
* bpo-31861: Fix possible crash in PyAnextAwaitable_New (GH-25005)Pablo Galindo2021-03-241-1/+5
|
* bpo-43244: Add pycore_compile.h header file (GH-25000)Victor Stinner2021-03-231-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the compiler functions using "struct _mod" type, because the public AST C API was removed: * PyAST_Compile() * PyAST_CompileEx() * PyAST_CompileObject() * PyFuture_FromAST() * PyFuture_FromASTObject() These functions were undocumented and excluded from the limited C API. Rename functions: * PyAST_CompileObject() => _PyAST_Compile() * PyFuture_FromASTObject() => _PyFuture_FromAST() Moreover, _PyFuture_FromAST() is no longer exported (replace PyAPI_FUNC() with extern). _PyAST_Compile() remains exported for test_peg_generator. Remove also compatibility functions: * PyAST_Compile() * PyAST_CompileEx() * PyFuture_FromAST()
* bpo-31861: Add aiter and anext to builtins (#23847)Joshua Bronson2021-03-232-2/+121
| | | | | | Co-authored-by: jab <jab@users.noreply.github.com> Co-authored-by: Daniel Pope <mauve@mauveweb.co.uk> Co-authored-by: Justin Wang <justin39@gmail.com>
* bpo-43452: Micro-optimizations to PyType_Lookup (GH-24804)Dino Viehland2021-03-201-28/+23
| | | | | | | | | The common case going through _PyType_Lookup is to have a cache hit. There are some small tweaks that can make this a little cheaper: * The name field identity is used for a cache hit and is kept alive by the cache. So there's no need to read the hash code o the name - instead, the address can be used as the hash. * There's no need to check if the name is cachable on the lookup either, it probably is, and if it is, it'll be in the cache. * If we clear the version tag when invalidating a type then we don't actually need to check for a valid version tag bit.
* bpo-43494: Make some minor changes to lnotab notes (GH-24861)Skip Montanaro2021-03-191-6/+6
| | | | This cleanup makes no substantive changes.
* bpo-43541: Fix PyEval_EvalCodeEx() regression (GH-24918)Victor Stinner2021-03-182-2/+2
| | | | | | | | | | | * Remove an assertion which required CO_NEWLOCALS and CO_OPTIMIZED code flags. It is ok to call this function on a code with these flags set. * Fix reference counting on builtins: remove Py_DECREF(). Fix regression introduced in the commit 46496f9d12582bf11f4911ad0f23315d6f277907. Add also a comment to document that _PyEval_BuiltinsFromGlobals() returns a borrowed reference.
* bpo-35883: Py_DecodeLocale() escapes invalid Unicode characters (GH-24843)Victor Stinner2021-03-171-4/+5
| | | | | | | | | | Python no longer fails at startup with a fatal error if a command line argument contains an invalid Unicode character. The Py_DecodeLocale() function now escapes byte sequences which would be decoded as Unicode characters outside the [U+0000; U+10ffff] range. Use MAX_UNICODE constant in unicodeobject.c.
* bpo-43441: Fix _PyType_ClearCache() for subinterpreters (GH-24822)junyixie2021-03-131-5/+10
| | | | | _PyType_ClearCache() now only resets next_version_tag in the main interpreter. Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-42128: Add __match_args__ to structseq-based classes (GH-24732)Pablo Galindo2021-03-041-0/+34
|
* bpo-11717: fix ssize_t redefinition error when targeting 32bit Windows app ↵Jozef Grajciar2021-03-011-1/+1
| | | | (GH-24479)
* bpo-41972: Use the two-way algorithm for string searching (GH-22904)Dennis Sweeney2021-02-282-20/+901
| | | | | Implement an enhanced variant of Crochemore and Perrin's Two-Way string searching algorithm, which reduces worst-case time from quadratic (the product of the string and pattern lengths) to linear. This applies to forward searches (like``find``, ``index``, ``replace``); the algorithm for reverse searches (like ``rfind``) is not changed. Co-authored-by: Tim Peters <tim.peters@gmail.com>
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-2610-11/+24
| | | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-38302: __pow__/__rpow__ now called when __ipow__ returns NotImplemented ↵Alex2021-02-261-21/+27
| | | | (#16459)
* bpo-42808: Add PyType_Type.tp_vectorcall for type(obj) performance (GH-24058)Dennis Sweeney2021-02-221-0/+18
|
* bpo-42093: Cleanup _PyDict_GetItemHint() (GH-24582)Victor Stinner2021-02-211-31/+4
| | | | | | * No longer save/restore the current exception. It is no longer used with an exception raised. * No longer clear the current exception on error: it's now up to the caller.
* bpo-43277: Add PySet_CheckExact to the C-API (GH-24598)Pablo Galindo2021-02-202-2/+2
| | | For some mysterious reason we have PySet_Check, PyFrozenSet_Check, PyAnySet_Check, PyAnySet_CheckExact and PyFrozenSet_CheckExact but no PySet_CheckExact.
* bpo-42990: Functions inherit current builtins (GH-24564)Victor Stinner2021-02-202-17/+10
| | | | | | | | | | | | | | | | | | | | The types.FunctionType constructor now inherits the current builtins if the globals dictionary has no "__builtins__" key, rather than using {"None": None} as builtins: same behavior as eval() and exec() functions. Defining a function with "def function(...): ..." in Python is not affected, globals cannot be overriden with this syntax: it also inherits the current builtins. PyFrame_New(), PyEval_EvalCode(), PyEval_EvalCodeEx(), PyFunction_New() and PyFunction_NewWithQualName() now inherits the current builtins namespace if the globals dictionary has no "__builtins__" key. * Add _PyEval_GetBuiltins() function. * _PyEval_BuiltinsFromGlobals() now uses _PyEval_GetBuiltins() if builtins cannot be found in globals. * Add tstate parameter to _PyEval_BuiltinsFromGlobals().
* bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner2021-02-1912-60/+59
| | | | | | | | | | | | | | | Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
* bpo-43268: _Py_IsMainInterpreter() now expects interp (GH-24577)Victor Stinner2021-02-193-3/+3
| | | | The _Py_IsMainInterpreter() function now expects interp rather than tstate.
* bpo-42990: Refactor _PyFrame_New_NoTrack() (GH-24566)Victor Stinner2021-02-182-103/+102
| | | | | | | | | | | | * Refactor _PyFrame_New_NoTrack() and PyFunction_NewWithQualName() code. * PyFrame_New() checks for _PyEval_BuiltinsFromGlobals() failure. * Fix a ref leak in _PyEval_BuiltinsFromGlobals() error path. * Complete PyFunction_GetModule() documentation: it returns a borrowed reference and it can return NULL. * Move _PyEval_BuiltinsFromGlobals() definition to the internal C API. * PyFunction_NewWithQualName() uses _Py_IDENTIFIER() API for the "__name__" string to make it compatible with subinterpreters.
* bpo-42990: Add __builtins__ attribute to functions (GH-24559)Victor Stinner2021-02-181-0/+1
| | | | | | Expose the new PyFunctionObject.func_builtins member in Python as a new __builtins__ attribute on functions. Document also the behavior change in What's New in Python 3.10.
* bpo-40170: Always define PyExceptionClass_Name() as a function (GH-24553)Erlend Egeberg Aasland2021-02-171-2/+0
| | | Remove macro variant of PyExceptionClass_Name().
* bpo-40170: Always define PyIter_Check() as a function (GH-24548)Erlend Egeberg Aasland2021-02-161-5/+5
|
* bpo-40170: Convert PyDescr_IsData() to static inline function (GH-24535)Erlend Egeberg Aasland2021-02-161-0/+5
|
* bpo-42990: Further refactoring of PyEval_ functions. (GH-24368)Mark Shannon2021-02-013-101/+31
| | | | | | | | | | * Further refactoring of PyEval_EvalCode and friends. Break into make-frame, and eval-frame parts. * Simplify function vector call using new _PyEval_Vector. * Remove unused internal functions: _PyEval_EvalCodeWithName and _PyEval_EvalCode. * Don't use legacy function PyEval_EvalCodeEx.
* bpo-40455: Fix gcc10+ warning about writing into a section of offset 0 ↵Pablo Galindo2021-01-301-2/+2
| | | | (GH-24384)