pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/150308/files

t" href="https://github.githubassets.com/assets/code-34e10031edc15af1.css" /> [3.14] gh-148450: abc.register needs to update type_version when tp_flags is changed (GH-148623) by cocolato · Pull Request #150308 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Tests for the internal type cache in CPython. """
import collections.abc
import dis
import unittest
import warnings
Expand Down Expand Up @@ -114,6 +115,25 @@ class HolderSub(Holder):
Holder.set_value()
HolderSub.value

def test_abc_register_invalidates_subclass_versions(self):
class Parent:
pass

class Child(Parent):
pass

type_assign_version(Parent)
type_assign_version(Child)
parent_version = type_get_version(Parent)
child_version = type_get_version(Child)
if parent_version == 0 or child_version == 0:
self.skipTest("Could not assign valid type versions")

collections.abc.Mapping.register(Parent)

self.assertEqual(type_get_version(Parent), 0)
self.assertEqual(type_get_version(Child), 0)

@support.cpython_only
class TypeCacheWithSpecializationTests(unittest.TestCase):
def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``abc.register()`` so it invalidates type version tags for registered classes.
9 changes: 9 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6066,6 +6066,15 @@ void
_PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask, unsigned long flags)
{
BEGIN_TYPE_LOCK();
/* Ideally, changing flags and invalidating the old version tag would happen
in one step. In 3.14, invalidate first while holding TYPE_LOCK so readers
cannot assign a fresh tag from stale flags. Immutable types are skipped by
set_flags_recursive(). */
if (!PyType_HasFeature(self, Py_TPFLAGS_IMMUTABLETYPE) &&
(self->tp_flags & mask) != flags)
{
type_modified_unlocked(self);
}
set_flags_recursive(self, mask, flags);
END_TYPE_LOCK();
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy