summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* bpo-44657: Fix instancemethod_call to use PyInstanceMethod_GET_FUNCTION ↵Miss Islington (bot)2021-07-281-1/+1
| | | | | | | (GH-27202) (cherry picked from commit ddf8ae31a0f371eff2db14c7f7a45976b86d56ea) Co-authored-by: Dong-hee Na <donghee.na@python.org>
* bpo-34013: Move the Python 2 hints from the exception constructor to the ↵Miss Islington (bot)2021-07-271-201/+0
| | | | | | | parser (GH-27392) (cherry picked from commit ecc3c8e4216958d85385bf2467441c975128f26c) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-44698: Fix undefined behaviour in complex exponentiation. (GH-27278) ↵Miss Islington (bot)2021-07-261-8/+15
| | | | | | | (#27366) (cherry picked from commit 1d582bbc969e05896addf97844ddf17ce9830e5e) Co-authored-by: T. Wouters <thomas@python.org>
* bpo-44732: Rename types.Union to types.UnionType (GH-27342)Miss Islington (bot)2021-07-261-3/+3
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 2b8ad9e6c5f0a66e9ca2d15f85336d8a3eefefb0) Co-authored-by: Hasan <hasan.aleeyev@gmail.com>
* bpo-44676: Serialize the union type using only public API (GH-27323) (GH-27340)Miss Islington (bot)2021-07-241-48/+0
| | | | | | | Remove also the _from_args() constructor. (cherry picked from commit 435a0334d341e5f8faed594d9f015746bb7845db) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44731: Simplify the union type implementation (GH-27318) (GH-27334)Ken Jin2021-07-241-81/+7
| | | | | Remove direct support of typing types in the C code because they are already supported by defining methods __or__ and __ror__ in the Python code. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.10] bpo-44676: Add ability to serialize types.Union (GH-27244) (GH-27333)Pablo Galindo Salgado2021-07-241-0/+51
| | | | | (cherry picked from commit fe13f0b0f696464dd6f283576668dbf57cb11399) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ ↵Miss Islington (bot)2021-07-241-0/+6
| | | | | | | (GH-27316) (GH-27324) (cherry picked from commit 5370f0a82aaa4ba617070d5c71d2b18236096ac0) Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
* bpo-42747: Remove Py_TPFLAGS_HAVE_AM_SEND and make ↵Miss Islington (bot)2021-07-233-30/+6
| | | | | | | | | | | | | | | Py_TPFLAGS_HAVE_VERSION_TAG no-op (GH-27260) (GH-27306) * Remove code that checks Py_TPFLAGS_HAVE_VERSION_TAG The field is always present in the type struct, as explained in the added comment. * Remove Py_TPFLAGS_HAVE_AM_SEND The flag is not needed, and since it was added in 3.10 it can be removed now. (cherry picked from commit a4760cc32d9e5dac7be262e9736eb30502cd7be3) Co-authored-by: Petr Viktorin <encukou@gmail.com>
* bpo-44653: Support typing types in parameter substitution in the union type. ↵Miss Islington (bot)2021-07-221-13/+12
| | | | | | | (GH-27247) (#27296) (cherry picked from commit 2e3744d50b6e30ea24351e55b4352dcc58fd469e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44633: Fix parameter substitution of the union type with wrong types. ↵Miss Islington (bot)2021-07-181-16/+28
| | | | | | | | | (GH-27218) (GH-27224) A TypeError is now raised instead of returning NotImplemented. (cherry picked from commit 3ea5332a4365bdd771286b3e9692495116e9ceef) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.10] bpo-44654: Refactor and clean up the union type implementation ↵Miss Islington (bot)2021-07-175-99/+55
| | | | | | (GH-27196) (GH-27219) (cherry picked from commit 0fd27375cabd12e68a2f12cfeca11a2d5043429e)
* [3.10] bpo-44490: Add __parameters__ and __getitem__ to types.Union ↵Serhiy Storchaka2021-07-172-19/+84
| | | | | | | | | | | (GH-26980) (GH-27207) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>. (cherry picked from commit c45fa1a5d9b419cf13ad4b5a7cb453956495b83e) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* [3.10] bpo-44652: Preserve natural order of args in the union type. ↵Serhiy Storchaka2021-07-161-2/+2
| | | | | | | (GH-27185) (GH-27190) (cherry picked from commit 0cd2d51aadcd2a0c0739a5df0a6235d64f35619e) Automerge-Triggered-By: GH:ambv
* [3.10] bpo-44636: Collapse union of equal types (GH-27178) (GH-27181)Serhiy Storchaka2021-07-161-8/+16
| | | | | | | | The result of `int | int` is now `int`. Fix comparison of the union type with non-hashable objects. `int | str == {}` no longer raises a TypeError. (cherry picked from commit d9f923280f204204f8703756aef4f655b579b4b8)
* bpo-44646: Fix the hash of the union type. (GH-27179) (#27180)Miss Islington (bot)2021-07-161-4/+6
| | | | | | | | | It no longer depends on the order of arguments. hash(int | str) == hash(str | int) Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com> (cherry picked from commit aeaa553d650786afc6e68df1f4813ae1a5b71d05) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44184: Apply GH-26274 to the non-GC-type branch of subtype_dealloc ↵Miss Islington (bot)2021-07-151-3/+11
| | | | | | | | | | | (GH-27165) (GH-27174) The non-GC-type branch of subtype_dealloc is using the type of an object after freeing in the same unsafe way as GH-26274 fixes. (I believe the old news entry covers this change well enough.) https://bugs.python.org/issue44184 (cherry picked from commit 074e7659f208051b6b973f7fdb654dd22b93aaa2) Co-authored-by: T. Wouters <thomas@python.org>
* bpo-42073: allow classmethod to wrap other classmethod-like descriptors ↵Miss Islington (bot)2021-07-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-27115) (GH-27162) Patch by Erik Welch. bpo-19072 (GH-8405) allows `classmethod` to wrap other descriptors, but this does not work when the wrapped descriptor mimics classmethod. The current PR fixes this. In Python 3.8 and before, one could create a callable descriptor such that this works as expected (see Lib/test/test_decorators.py for examples): ```python class A: @myclassmethod def f1(cls): return cls @classmethod @myclassmethod def f2(cls): return cls ``` In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, it returns `type(A)`. This PR make `A.f2()` return `A` again. As of GH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`. This allows one to chain `@classmethod` and `@property` together. When using classmethod-like descriptors, it's the second argument to `__get__`--the owner or the type--that is important, but this argument is currently missing. Since it is None, the "owner" argument is assumed to be the type of the first argument, which, in this case, is wrong (we want `A`, not `type(A)`). This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has `__get__`. Co-authored-by: Erik Welch <erik.n.welch@gmail.com> (cherry picked from commit b83861f0265e07207a6ae2c49c40fa8f447893f2)
* bpo-44632: Fix support of TypeVar in the union type (GH-27139) (GH-27143)Miss Islington (bot)2021-07-151-1/+1
| | | | | | | | int | TypeVar('T') returns now an instance of types.Union instead of typing.Union. (cherry picked from commit a158b20019b50e3ece6e4743ec4e6ae8d818b690) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.10] bpo-44635: Convert None to NoneType in the union type constructor ↵Serhiy Storchaka2021-07-151-9/+7
| | | | | | (GH-27136). (GH-27142) (cherry picked from commit b81cac05606c84958b52ada09f690463a3c7e949)
* bpo-44606: Fix __instancecheck__ and __subclasscheck__ for the union type. ↵Miss Islington (bot)2021-07-141-4/+19
| | | | | | | | | | | | (GH-27120) * Fix issubclass() for None. E.g. issubclass(type(None), int | None) returns now True. * Fix issubclass() for virtual subclasses. E.g. issubclass(dict, int | collections.abc.Mapping) returns now True. * Fix crash in isinstance() if the check for one of items raises exception. (cherry picked from commit 81989058de381108dfd0a4255b93d4fb34417002) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* 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>