summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-44562: Use PyType_GenericAlloc in Py_GenericAlias (GH-27021)Miss Islington (bot)2021-07-051-2/+2
| | | | | | | | | | | | * bpo-44562: Use PyType_GenericAlloc in Py_GenericAlias * Update Objects/genericaliasobject.c Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit b324c4c5f763c5116a97db8591e6dcb94456570a) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44562: Remove invalid PyObject_GC_Del from error path of ↵Miss Islington (bot)2021-07-041-3/+3
| | | | | | | types.GenericAlias … (GH-27016) (cherry picked from commit d33943a6c368c2184e238019c63ac7a267da5594) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44553: Correct failure in tp_new for the union object (GH-27008) (GH-27009)Miss Islington (bot)2021-07-031-2/+2
| | | | | | | (cherry picked from commit bc3961485639cc73de7c4c7eed1b56f3c74939bf) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44553 : Implement GC methods for types.Union (GH-26993)Miss Islington (bot)2021-07-031-4/+17
| | | | | (cherry picked from commit 1097384ce964dd63686b1aac706cd0fa764c2dc9) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44523: Remove the pass-through for hash() in weakref proxy objects ↵Miss Islington (bot)2021-06-291-16/+2
| | | | | | | (GH-26950) (cherry picked from commit e2fea101fd5517f33371b04432842b971021c3bf) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44483: Fix crash in union object with bad ``__module__`` (GH-26848) ↵Miss Islington (bot)2021-06-231-3/+14
| | | | | | | | (GH-26852) (cherry picked from commit adfa1ba398c74720b42f16f06fd3ec0353599fa5) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* [3.10] Fix a potential reference-counting bug in long_pow (GH-26690) (GH-26703)Mark Dickinson2021-06-131-0/+1
| | | | | (cherry picked from commit 59242431991794064824cf2ab70886367613f29e) Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
* [3.10] Add more const modifiers. (GH-26691). (GH-26692)Serhiy Storchaka2021-06-122-4/+4
| | | | | (cherry picked from commit be8b631b7a587aa781245e14c8cca32970e1be5b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44232: Fix type_new() error reporting (GH-26359) (GH-26365)Miss Islington (bot)2021-05-261-0/+4
| | | | | | | | | Fix a regression in type() when a metaclass raises an exception. The C function type_new() must properly report the exception when a metaclass constructor raises an exception and the winner class is not the metaclass. (cherry picked from commit bd199e72fb60a8ff001a023f23925092a290be91) Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-44184: Fix subtype_dealloc() for freed type (GH-26274) (GH-26290)Miss Islington (bot)2021-05-211-2/+9
| | | | | | | | | | | | | | Fix a crash at Python exit when a deallocator function removes the last strong reference to a heap type. Don't read type memory after calling basedealloc() since basedealloc() can deallocate the type and free its memory. _PyMem_IsPtrFreed() argument is now constant. (cherry picked from commit 615069eb08494d089bf24e43547fbc482ed699b8) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-44114: Remove redundant cast. (GH-26098)Miss Islington (bot)2021-05-131-2/+2
| | | | | (cherry picked from commit e0c614e5fd017ca43cab55a9f8490133750c704f) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
* bpo-44114: Fix dictkeys_reversed and dictvalues_reversed function signatures ↵Miss Islington (bot)2021-05-131-4/+4
| | | | | | | | | | (GH-26062) These are passed and called as PyCFunction, however they are defined here without the (ignored) args parameter. This works fine in some C compilers, but fails in webassembly or anything else that has strict function pointer call type checking. (cherry picked from commit ab383eb6f03896b0ef6634ee3d776344fcb9e5b8) Co-authored-by: Joe Marshall <joe.marshall@nottingham.ac.uk>
* bpo-43916: Move the _PyStructSequence_InitType function to the internal API ↵Pablo Galindo2021-05-031-0/+1
| | | | (GH-25854)
* bpo-43977: Make sure that tp_flags for pattern matching are inherited ↵Mark Shannon2021-05-021-6/+12
| | | | correctly. (GH-25813)
* bpo-43901: Fix refleaks in test_module (GH-25754)Pablo Galindo2021-04-301-4/+11
|
* bpo-43908: check_set_special_type_attr() checks Py_TPFLAGS_IMMUTABLETYPE ↵Erlend Egeberg Aasland2021-04-301-7/+11
| | | | | | | | (GH-25743) check_set_special_type_attr() and type_set_annotations() now check for immutable flag (Py_TPFLAGS_IMMUTABLETYPE). Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-43667: Fix broken Unicode encoding in non-UTF locales on Solaris (GH-25096)Jakub Kulík2021-04-301-0/+40
|
* bpo-43916: PyStdPrinter_Type uses Py_TPFLAGS_DISALLOW_INSTANTIATION (GH-25749)Victor Stinner2021-04-301-27/+4
| | | | | | | The PyStdPrinter_Type type now uses the Py_TPFLAGS_DISALLOW_INSTANTIATION flag to disallow instantiation, rather than seting a tp_init method which always fail. Write also unit tests for PyStdPrinter_Type.
* bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag (GH-25721)Victor Stinner2021-04-302-34/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new Py_TPFLAGS_DISALLOW_INSTANTIATION type flag to disallow creating type instances: set tp_new to NULL and don't create the "__new__" key in the type dictionary. The flag is set automatically on static types if tp_base is NULL or &PyBaseObject_Type and tp_new is NULL. Use the flag on the following types: * _curses.ncurses_version type * _curses_panel.panel * _tkinter.Tcl_Obj * _tkinter.tkapp * _tkinter.tktimertoken * _xxsubinterpretersmodule.ChannelID * sys.flags type * sys.getwindowsversion() type * sys.version_info type Update MyStr example in the C API documentation to use Py_TPFLAGS_DISALLOW_INSTANTIATION. Add _PyStructSequence_InitType() function to create a structseq type with the Py_TPFLAGS_DISALLOW_INSTANTIATION flag set. type_new() calls _PyType_CheckConsistency() at exit.
* bpo-43973: object_set_class() checks Py_TPFLAGS_IMMUTABLETYPE (GH-25714)Erlend Egeberg Aasland2021-04-301-3/+3
| | | Use Py_TPFLAGS_IMMUTABLETYPE to check for class assignments.
* bpo-43977: Use tp_flags for collection matching (GH-25723)Mark Shannon2021-04-307-7/+14
| | | | | | | | | | | | | * Add Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING, add to all relevant standard builtin classes. * Set relevant flags on collections.abc.Sequence and Mapping. * Use flags in MATCH_SEQUENCE and MATCH_MAPPING opcodes. * Inherit Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING. * Add NEWS * Remove interpreter-state map_abc and seq_abc fields.
* Two minor fixes for accessing a module's name. (#25658)larryhastings2021-04-301-6/+2
| | | | | | | | | | | | | | | | | While working on another issue, I noticed two minor nits in the C implementation of the module object. Both are related to getting a module's name. First, the C function module_dir() (module.__dir__) starts by ensuring the module dict is valid. If the module dict is invalid, it wants to format an exception using the name of the module, which it gets from PyModule_GetName(). However, PyModule_GetName() gets the name of the module from the dict. So getting the name in this circumstance will never succeed. When module_dir() wants to format the error but can't get the name, it knows that PyModule_GetName() must have already raised an exception. So it leaves that exception alone and returns an error. The end result is that the exception raised here is kind of useless and misleading: dir(module) on a module with no __dict__ raises SystemError("nameless module"). I changed the code to actually raise the exception it wanted to raise, just without a real module name: TypeError("<module>.__dict__ is not a dictionary"). This seems more useful, and would do a better job putting the programmer who encountered this on the right track of figuring out what was going on. Second, the C API function PyModule_GetNameObject() checks to see if the module has a dict. If m->md_dict is not NULL, it calls _PyDict_GetItemIdWithError(). However, it's possible for m->md_dict to be None. And if you call _PyDict_GetItemIdWithError(Py_None, ...) it will *crash*. Unfortunately, this crash was due to my own bug in the other branch. Fixing my code made the crash go away. I assert that this is still possible at the API level. The fix is easy: add a PyDict_Check() to PyModule_GetNameObject(). Unfortunately, I don't know how to add a unit test for this. Having changed module_dir() above, I can't find any other interfaces callable from Python that eventually call PyModule_GetNameObject(). So I don't know how to trick the runtime into reproducing this error. Since both these changes are minor--each entails only a small edit to only one line--I didn't bother with a news item.
* bpo-43901: Lazy-create an empty annotations dict in all unannotated user ↵larryhastings2021-04-302-3/+138
| | | | | classes and modules (#25623) Change class and module objects to lazy-create empty annotations dicts on demand. The annotations dicts are stored in the object's `__dict__` for backwards compatibility.
* bpo-42800: Rename AUDIT_READ to PY_AUDIT_READ (GH-25736)Steve Dower2021-04-303-8/+8
|
* bpo-42800: add audit hooks for f_code and tb_frame (GH-24182)Ryan Hileman2021-04-293-8/+8
| | | | | | | | | | Accessing the following attributes will now fire PEP 578 style audit hooks as ("object.__getattr__", obj, name): * PyTracebackObject: tb_frame * PyFrameObject: f_code * PyGenObject: gi_code, gi_frame * PyCoroObject: cr_code, cr_frame * PyAsyncGenObject: ag_code, ag_frame Add an AUDIT_READ attribute flag aliased to READ_RESTRICTED. Update obsolete flag documentation.
* bpo-43933: Show frame.f_lineno as None, rather than -1, if there is no line ↵Mark Shannon2021-04-291-1/+7
| | | | number. (GH-25717)
* bpo-42739: Don't use sentinels to mark end of line table. (GH-25657)Mark Shannon2021-04-292-24/+21
| | | | | * Add length parameter to PyLineTable_InitAddressRange and doen't use sentinel values at end of table. Makes the line number table more robust. * Update PyCodeAddressRange to match PEP 626.
* bpo-24275: Don't downgrade unicode-only dicts to mixed on lookups (GH-25186)Hristo Venev2021-04-291-3/+6
|
* bpo-43908: Add Py_TPFLAGS_IMMUTABLETYPE flag (GH-25520)Erlend Egeberg Aasland2021-04-281-1/+6
| | | | | | Introduce Py_TPFLAGS_IMMUTABLETYPE flag for immutable type objects, and modify PyType_Ready() to set it for static types. Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-41559: Change PEP 612 implementation to pure Python (#25449)Ken Jin2021-04-281-62/+14
|
* bpo-43962: Fix _PyInterpreterState_IDIncref() (GH-25683)Victor Stinner2021-04-281-3/+9
| | | | _PyInterpreterState_IDIncref() now calls _PyInterpreterState_IDInitref() and always increments id_refcount.
* bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo2021-04-231-17/+28
| | | | | | | | | | | | | | | | | To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
* bpo-43475: Fix worst case collision behavior for NaN instances (GH-25493)Raymond Hettinger2021-04-222-3/+3
|
* bpo-40137: Add pycore_moduleobject.h internal header (GH-25507)Victor Stinner2021-04-213-18/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add pycore_moduleobject.h internal header file with static inline functions to access module members: * _PyModule_GetDict() * _PyModule_GetDef() * _PyModule_GetState() These functions don't check at runtime if their argument has a valid type and can be inlined even if Python is not built with LTO. _PyType_GetModuleByDef() uses _PyModule_GetDef(). Replace PyModule_GetState() with _PyModule_GetState() in the extension modules, considered as performance sensitive: * _abc * _functools * _operator * _pickle * _queue * _random * _sre * _struct * _thread * _winapi * array * posix The following extensions are now built with the Py_BUILD_CORE_MODULE macro defined, to be able to use the internal pycore_moduleobject.h header: _abc, array, _operator, _queue, _sre, _struct.
* bpo-40137: Optimize _PyType_GetModuleByDef() loop (GH-25505)Victor Stinner2021-04-211-5/+21
| | | | | | | PyType_Ready() now ensures that a type MRO cannot be empty. _PyType_GetModuleByDef() no longer checks "i < PyTuple_GET_SIZE(mro)" at the first loop iteration to optimize the most common case, when the argument is the defining class.
* bpo-40137: _PyType_GetModuleByDef() doesn't check tp_flags (GH-25504)Victor Stinner2021-04-211-15/+14
| | | | | | | | _PyType_GetModuleByDef() no longer checks if types are heap types. _PyType_GetModuleByDef() must only be called on a heap type created by PyType_FromModuleAndSpec() or on its subclasses. type_ready_mro() ensures that a static type cannot inherit from a heap type.
* 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
|