chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
81f07907-3757-4594-8923-84ad538374af | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,416 | supabase-export-v2 | 6437cb74dc2cdfa6 | >>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled Traceback (most recent call last): ... ValueError: Expected 'metle' to be one of {'metal', 'plastic', 'wood'}
>>> Component('WIDGET', 'metal', -5) # Blocked: -5 is negative
Traceback (most recent call last):
... ValueError: Expected -5 to be at leas... | trusted_official_docs | CPython Docs | >>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled Traceback (most recent call last): ... ValueError: Expected 'metle' to be one of {'metal', 'plastic', 'wood'}
>>> Component('WIDGET', 'metal', -5) # Blocked: -5 is negative
Traceback (most recent call last):
... ValueError: Expected -5 to be at leas... | >>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled Traceback (most recent call last): ... ValueError: Expected 'metle' to be one of {'metal', 'plastic', 'wood'}
>>> Component('WIDGET', 'metal', -5) # Blocked: -5 is negative
Traceback (most recent call last):
... ValueError: Expected -5 to be at leas... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
83ecef92-6fa4-4047-83d4-e58d6a3757ec | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,519 | supabase-export-v2 | 69130a81898ecf2d | import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE Music (title text, artist text, year integer);')
conn.execute('CREATE INDEX MusicNdx ON Music (title);')
conn.executemany('INSERT INTO Music VALUES (?, ?, ?);', song_data)
conn.execute('CREATE TABLE Movies (title text, director text, year ... | trusted_official_docs | CPython Docs | import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE Music (title text, artist text, year integer);')
conn.execute('CREATE INDEX MusicNdx ON Music (title);')
conn.executemany('INSERT INTO Music VALUES (?, ?, ?);', song_data)
conn.execute('CREATE TABLE Movies (title text, director text, year ... | import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE Music (title text, artist text, year integer);')
conn.execute('CREATE INDEX MusicNdx ON Music (title);')
conn.executemany('INSERT INTO Music VALUES (?, ?, ?);', song_data)
conn.execute('CREATE TABLE Movies (title text, director text, year ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84612a18-afa4-4f9e-831b-9806918f5bd9 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,679 | supabase-export-v2 | b8fa3095332bca9b | def __delete__(self, obj): 'Emulate member_delete() in Objects/descrobject.c' value = obj._slotvalues[self.offset] if value is null: raise AttributeError(self.name) obj._slotvalues[self.offset] = null
def __repr__(self):
'Emulate member_repr() in Objects/descrobject.c'
return f'<Member {self.name!r} of {self.clsname!... | trusted_official_docs | CPython Docs | def __delete__(self, obj): 'Emulate member_delete() in Objects/descrobject.c' value = obj._slotvalues[self.offset] if value is null: raise AttributeError(self.name) obj._slotvalues[self.offset] = null
def __repr__(self):
'Emulate member_repr() in Objects/descrobject.c'
return f'<Member {self.name!r} of {self.clsname!... | def __delete__(self, obj): 'Emulate member_delete() in Objects/descrobject.c' value = obj._slotvalues[self.offset] if value is null: raise AttributeError(self.name) obj._slotvalues[self.offset] = null
def __repr__(self):
'Emulate member_repr() in Objects/descrobject.c'
return f'<Member {self.name!r} of {self.clsname!... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84a019a0-5c6d-418a-84af-90a736d38990 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,436 | supabase-export-v2 | 91df6a4dd89654b6 | with the :meth:`~object.__set__` raising an :exc:`AttributeError` when called. Defining the :meth:`~object.__set__` method with an exception raising placeholder is enough to make it a data descriptor.
Overview of descriptor invocation
--------------------------------- | trusted_official_docs | CPython Docs | with the :meth:`~object.__set__` raising an :exc:`AttributeError` when called. Defining the :meth:`~object.__set__` method with an exception raising placeholder is enough to make it a data descriptor.
Overview of descriptor invocation
--------------------------------- | with the :meth:`~object.__set__` raising an :exc:`AttributeError` when called. Defining the :meth:`~object.__set__` method with an exception raising placeholder is enough to make it a data descriptor.
Overview of descriptor invocation
--------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
87f2c012-63ad-4d47-934c-b6b064b8a004 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,432 | supabase-export-v2 | 0787ed1a2c9fa64b | ``descr.__delete__(self, obj)``
That is all there is to it. Define any of these methods and an object is
considered a descriptor and can override default behavior upon being looked up
as an attribute. | trusted_official_docs | CPython Docs | ``descr.__delete__(self, obj)``
That is all there is to it. Define any of these methods and an object is
considered a descriptor and can override default behavior upon being looked up
as an attribute. | ``descr.__delete__(self, obj)``
That is all there is to it. Define any of these methods and an object is
considered a descriptor and can override default behavior upon being looked up
as an attribute. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8b5c62f1-e7cd-4ba2-86ef-eb4709e5544b | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,549 | supabase-export-v2 | 8b75c2262b35cb57 | property.") no_setter = Property(getx, None, delx, "I'm the 'x' property.") no_deleter = Property(getx, setx, None, "I'm the 'x' property.") no_doc = Property(getx, setx, delx, None)
# Now do it again but use the decorator style | trusted_official_docs | CPython Docs | property.") no_setter = Property(getx, None, delx, "I'm the 'x' property.") no_deleter = Property(getx, setx, None, "I'm the 'x' property.") no_doc = Property(getx, setx, delx, None)
# Now do it again but use the decorator style | property.") no_setter = Property(getx, None, delx, "I'm the 'x' property.") no_deleter = Property(getx, setx, None, "I'm the 'x' property.") no_doc = Property(getx, setx, delx, None)
# Now do it again but use the decorator style | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8b7a0057-554d-4ebd-bb16-b8c2fb23f03f | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,597 | supabase-export-v2 | c58b063adf6042af | they can be converted to a method when accessed as attributes. The non-data descriptor transforms an ``obj.f(*args)`` call into ``f(obj, *args)``. Calling ``cls.f(*args)`` becomes ``f(*args)``.
This chart summarizes the binding and its two most useful variants: | trusted_official_docs | CPython Docs | they can be converted to a method when accessed as attributes. The non-data descriptor transforms an ``obj.f(*args)`` call into ``f(obj, *args)``. Calling ``cls.f(*args)`` becomes ``f(*args)``.
This chart summarizes the binding and its two most useful variants: | they can be converted to a method when accessed as attributes. The non-data descriptor transforms an ``obj.f(*args)`` call into ``f(obj, *args)``. Calling ``cls.f(*args)`` becomes ``f(*args)``.
This chart summarizes the binding and its two most useful variants: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8ca5bf95-2838-4280-a3aa-26c419bbb8aa | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,423 | supabase-export-v2 | a300a462c224872b | Defines descriptors, summarizes the protocol, and shows how descriptors are called. Provides an example showing how object relational mappings work.
Learning about descriptors not only provides access to a larger toolset, it
creates a deeper understanding of how Python works. | trusted_official_docs | CPython Docs | Defines descriptors, summarizes the protocol, and shows how descriptors are called. Provides an example showing how object relational mappings work.
Learning about descriptors not only provides access to a larger toolset, it
creates a deeper understanding of how Python works. | Defines descriptors, summarizes the protocol, and shows how descriptors are called. Provides an example showing how object relational mappings work.
Learning about descriptors not only provides access to a larger toolset, it
creates a deeper understanding of how Python works. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8dec0d21-60c3-4412-90a9-88f75b64f406 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,330 | supabase-export-v2 | 1f463217b84b8baf | data is stored as a private attribute in the instance dictionary. The descriptor's :meth:`~object.__get__` and :meth:`~object.__set__` methods are triggered when the public attribute is accessed.
In the following example, *age* is the public attribute and *_age* is the
private attribute. When the public attribute is ac... | trusted_official_docs | CPython Docs | data is stored as a private attribute in the instance dictionary. The descriptor's :meth:`~object.__get__` and :meth:`~object.__set__` methods are triggered when the public attribute is accessed.
In the following example, *age* is the public attribute and *_age* is the
private attribute. When the public attribute is ac... | data is stored as a private attribute in the instance dictionary. The descriptor's :meth:`~object.__get__` and :meth:`~object.__set__` methods are triggered when the public attribute is accessed.
In the following example, *age* is the public attribute and *_age* is the
private attribute. When the public attribute is ac... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
92f70d2f-f4ab-4bd3-a108-c7365230bddf | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,534 | supabase-export-v2 | 3f483f78b1272aee | .. doctest:: :hide:
>>> C.x.__doc__
"I'm the 'x' property."
>>> c.x = 2.71828
>>> c.x
2.71828
>>> del c.x
>>> c.x
Traceback (most recent call last):
... AttributeError: 'C' object has no attribute '_C__x' | trusted_official_docs | CPython Docs | .. doctest:: :hide:
>>> C.x.__doc__
"I'm the 'x' property."
>>> c.x = 2.71828
>>> c.x
2.71828
>>> del c.x
>>> c.x
Traceback (most recent call last):
... AttributeError: 'C' object has no attribute '_C__x' | .. doctest:: :hide:
>>> C.x.__doc__
"I'm the 'x' property."
>>> c.x = 2.71828
>>> c.x
2.71828
>>> del c.x
>>> c.x
Traceback (most recent call last):
... AttributeError: 'C' object has no attribute '_C__x' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93f5ba07-2a03-4650-bd08-4c2554acec27 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,603 | supabase-export-v2 | 7d6e5cd734195ca5 | not directly depend on a particular dataset. It can be called either from an object or the class: ``s.erf(1.5) --> 0.9332`` or ``Sample.erf(1.5) --> 0.9332``.
Since static methods return the underlying function with no changes, the
example calls are unexciting: | trusted_official_docs | CPython Docs | not directly depend on a particular dataset. It can be called either from an object or the class: ``s.erf(1.5) --> 0.9332`` or ``Sample.erf(1.5) --> 0.9332``.
Since static methods return the underlying function with no changes, the
example calls are unexciting: | not directly depend on a particular dataset. It can be called either from an object or the class: ``s.erf(1.5) --> 0.9332`` or ``Sample.erf(1.5) --> 0.9332``.
Since static methods return the underlying function with no changes, the
example calls are unexciting: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93fcfa58-c241-4321-be7c-2e43c123abbc | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,379 | supabase-export-v2 | b3f3f802b7d7a524 | The main motivation for descriptors is to provide a hook allowing objects stored in class variables to control what happens during attribute lookup.
Traditionally, the calling class controls what happens during lookup. Descriptors invert that relationship and allow the data being looked-up to
have a say in the matter. | trusted_official_docs | CPython Docs | The main motivation for descriptors is to provide a hook allowing objects stored in class variables to control what happens during attribute lookup.
Traditionally, the calling class controls what happens during lookup. Descriptors invert that relationship and allow the data being looked-up to
have a say in the matter. | The main motivation for descriptors is to provide a hook allowing objects stored in class variables to control what happens during attribute lookup.
Traditionally, the calling class controls what happens during lookup. Descriptors invert that relationship and allow the data being looked-up to
have a say in the matter. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
974a21a6-19ef-4b89-9a39-ecdbf5b201e5 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,517 | supabase-export-v2 | 80fa7963539a487e | song_data = [ ('Country Roads', 'John Denver', 1972), ('Me and Bobby McGee', 'Janice Joplin', 1971), ('Coal Miners Daughter', 'Loretta Lynn', 1970), ]
movie_data = [
('Star Wars', 'George Lucas', 1977),
('Jaws', 'Steven Spielberg', 1975),
('Aliens', 'James Cameron', 1986),
] | trusted_official_docs | CPython Docs | song_data = [ ('Country Roads', 'John Denver', 1972), ('Me and Bobby McGee', 'Janice Joplin', 1971), ('Coal Miners Daughter', 'Loretta Lynn', 1970), ]
movie_data = [
('Star Wars', 'George Lucas', 1977),
('Jaws', 'Steven Spielberg', 1975),
('Aliens', 'James Cameron', 1986),
] | song_data = [ ('Country Roads', 'John Denver', 1972), ('Me and Bobby McGee', 'Janice Joplin', 1971), ('Coal Miners Daughter', 'Loretta Lynn', 1970), ]
movie_data = [
('Star Wars', 'George Lucas', 1977),
('Jaws', 'Steven Spielberg', 1975),
('Aliens', 'James Cameron', 1986),
] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
97841b14-13f6-46eb-ace9-985ac34c71d4 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,689 | supabase-export-v2 | 4d1ce56c1ce07b52 | 'Emulate _PyObject_GenericSetAttrWithDict() Objects/object.c' cls = type(self) if hasattr(cls, 'slot_names') and name not in cls.slot_names: raise AttributeError( f'{cls.__name__!r} object has no attribute {name!r}' ) super().__setattr__(name, value)
def __delattr__(self, name):
'Emulate _PyObject_GenericSetAttrWithDi... | trusted_official_docs | CPython Docs | 'Emulate _PyObject_GenericSetAttrWithDict() Objects/object.c' cls = type(self) if hasattr(cls, 'slot_names') and name not in cls.slot_names: raise AttributeError( f'{cls.__name__!r} object has no attribute {name!r}' ) super().__setattr__(name, value)
def __delattr__(self, name):
'Emulate _PyObject_GenericSetAttrWithDi... | 'Emulate _PyObject_GenericSetAttrWithDict() Objects/object.c' cls = type(self) if hasattr(cls, 'slot_names') and name not in cls.slot_names: raise AttributeError( f'{cls.__name__!r} object has no attribute {name!r}' ) super().__setattr__(name, value)
def __delattr__(self, name):
'Emulate _PyObject_GenericSetAttrWithDi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
97edc9b1-409b-40f8-9808-b5f3c1fbbab5 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,477 | supabase-export-v2 | 97315a530cdcb876 | attr): ... return attr.upper() ... >>> cw = ClassWithGetAttr() >>> cw.y = 456 >>> getattr_hook(cw, 'x') 123 >>> getattr_hook(cw, 'y') 456 >>> getattr_hook(cw, 'z') 'Z'
>>> class ClassWithoutGetAttr:
... x = 123
... >>> cwo = ClassWithoutGetAttr()
>>> cwo.y = 456
>>> getattr_hook(cwo, 'x')
123
>>> getattr_hook(cwo... | trusted_official_docs | CPython Docs | attr): ... return attr.upper() ... >>> cw = ClassWithGetAttr() >>> cw.y = 456 >>> getattr_hook(cw, 'x') 123 >>> getattr_hook(cw, 'y') 456 >>> getattr_hook(cw, 'z') 'Z'
>>> class ClassWithoutGetAttr:
... x = 123
... >>> cwo = ClassWithoutGetAttr()
>>> cwo.y = 456
>>> getattr_hook(cwo, 'x')
123
>>> getattr_hook(cwo... | attr): ... return attr.upper() ... >>> cw = ClassWithGetAttr() >>> cw.y = 456 >>> getattr_hook(cw, 'x') 123 >>> getattr_hook(cw, 'y') 456 >>> getattr_hook(cw, 'z') 'Z'
>>> class ClassWithoutGetAttr:
... x = 123
... >>> cwo = ClassWithoutGetAttr()
>>> cwo.y = 456
>>> getattr_hook(cwo, 'x')
123
>>> getattr_hook(cwo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9892bcd9-5c76-4049-b05a-899b7130a9af | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,497 | supabase-export-v2 | 7c88674acee3ddae | with two arguments. The *owner* is the class where the descriptor is used, and the *name* is the class variable the descriptor was assigned to.
The implementation details are in :c:func:`!type_new` and
:c:func:`!set_names` in :source:`Objects/typeobject.c`. | trusted_official_docs | CPython Docs | with two arguments. The *owner* is the class where the descriptor is used, and the *name* is the class variable the descriptor was assigned to.
The implementation details are in :c:func:`!type_new` and
:c:func:`!set_names` in :source:`Objects/typeobject.c`. | with two arguments. The *owner* is the class where the descriptor is used, and the *name* is the class variable the descriptor was assigned to.
The implementation details are in :c:func:`!type_new` and
:c:func:`!set_names` in :source:`Objects/typeobject.c`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9b6f364c-7f03-47dc-a638-7d0a68b913ba | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,635 | supabase-export-v2 | 01ab1e4643176899 | >>> d = Dict.fromkeys('abracadabra') >>> type(d) is Dict True >>> d {'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
Using the non-data descriptor protocol, a pure Python version of
:func:`classmethod` would look like this: | trusted_official_docs | CPython Docs | >>> d = Dict.fromkeys('abracadabra') >>> type(d) is Dict True >>> d {'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
Using the non-data descriptor protocol, a pure Python version of
:func:`classmethod` would look like this: | >>> d = Dict.fromkeys('abracadabra') >>> type(d) is Dict True >>> d {'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
Using the non-data descriptor protocol, a pure Python version of
:func:`classmethod` would look like this: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ca9ebc5-5669-41bb-ad80-91ae5fa919a1 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,414 | supabase-export-v2 | ca094cf5d88da8f5 | .. doctest::
>>> Component('Widget', 'metal', 5) # Blocked: 'Widget' is not all uppercase
Traceback (most recent call last):
... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget' | trusted_official_docs | CPython Docs | .. doctest::
>>> Component('Widget', 'metal', 5) # Blocked: 'Widget' is not all uppercase
Traceback (most recent call last):
... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget' | .. doctest::
>>> Component('Widget', 'metal', 5) # Blocked: 'Widget' is not all uppercase
Traceback (most recent call last):
... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9d478985-ea07-4481-8310-3e0eb3b0af57 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,425 | supabase-export-v2 | 13132cb29b39f45d | Definition and introduction ---------------------------
In general, a descriptor is an attribute value that has one of the methods in
the descriptor protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`,
and :meth:`~object.__delete__`. If any of those methods are defined for an
attribute, it is s... | trusted_official_docs | CPython Docs | Definition and introduction ---------------------------
In general, a descriptor is an attribute value that has one of the methods in
the descriptor protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`,
and :meth:`~object.__delete__`. If any of those methods are defined for an
attribute, it is s... | Definition and introduction ---------------------------
In general, a descriptor is an attribute value that has one of the methods in
the descriptor protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`,
and :meth:`~object.__delete__`. If any of those methods are defined for an
attribute, it is s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a827d282-c273-44f8-a6d6-eb28f28ef03e | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,566 | supabase-export-v2 | 991110be2f66e901 | object instance is prepended to the other arguments. By convention, the instance is called *self* but could be called *this* or any other variable name.
Methods can be created manually with :class:`types.MethodType` which is
roughly equivalent to: | trusted_official_docs | CPython Docs | object instance is prepended to the other arguments. By convention, the instance is called *self* but could be called *this* or any other variable name.
Methods can be created manually with :class:`types.MethodType` which is
roughly equivalent to: | object instance is prepended to the other arguments. By convention, the instance is called *self* but could be called *this* or any other variable name.
Methods can be created manually with :class:`types.MethodType` which is
roughly equivalent to: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a841a697-6c43-4553-91ae-2c6382088e2b | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,649 | supabase-export-v2 | 5778b81c0018612a | to the underlying function. Also it carries forward the attributes necessary to make the wrapper look like the wrapped function: :attr:`~function.__name__`, :attr:`~function.__qualname__`, :attr:`~function.__doc__`, and :attr:`~function.__annotations__`.
Member objects and __slots__
---------------------------- | trusted_official_docs | CPython Docs | to the underlying function. Also it carries forward the attributes necessary to make the wrapper look like the wrapped function: :attr:`~function.__name__`, :attr:`~function.__qualname__`, :attr:`~function.__doc__`, and :attr:`~function.__annotations__`.
Member objects and __slots__
---------------------------- | to the underlying function. Also it carries forward the attributes necessary to make the wrapper look like the wrapped function: :attr:`~function.__name__`, :attr:`~function.__qualname__`, :attr:`~function.__doc__`, and :attr:`~function.__annotations__`.
Member objects and __slots__
---------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8b88ce1-6c5f-41ed-a619-2ecae045aeeb | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,347 | supabase-export-v2 | f619f5350332f978 | and log the lookup INFO:root:Accessing 'age' giving 30 30 >>> mary.birthday() # Updates are logged as well INFO:root:Accessing 'age' giving 30 INFO:root:Updating 'age' to 31
>>> dave.name # Regular attribute lookup isn't logged
'David D'
>>> dave.age # Only the managed attribute is logged
INFO:root:Accessing 'age' g... | trusted_official_docs | CPython Docs | and log the lookup INFO:root:Accessing 'age' giving 30 30 >>> mary.birthday() # Updates are logged as well INFO:root:Accessing 'age' giving 30 INFO:root:Updating 'age' to 31
>>> dave.name # Regular attribute lookup isn't logged
'David D'
>>> dave.age # Only the managed attribute is logged
INFO:root:Accessing 'age' g... | and log the lookup INFO:root:Accessing 'age' giving 30 30 >>> mary.birthday() # Updates are logged as well INFO:root:Accessing 'age' giving 30 INFO:root:Updating 'age' to 31
>>> dave.name # Regular attribute lookup isn't logged
'David D'
>>> dave.age # Only the managed attribute is logged
INFO:root:Accessing 'age' g... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8d60d96-5854-4c94-85ae-5e070b2adbfb | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,478 | supabase-export-v2 | fb84bcec19bb8ede | 456 >>> getattr_hook(cwo, 'x') 123 >>> getattr_hook(cwo, 'y') 456 >>> getattr_hook(cwo, 'z') Traceback (most recent call last): ... AttributeError: 'ClassWithoutGetAttr' object has no attribute 'z'
Invocation from a class
----------------------- | trusted_official_docs | CPython Docs | 456 >>> getattr_hook(cwo, 'x') 123 >>> getattr_hook(cwo, 'y') 456 >>> getattr_hook(cwo, 'z') Traceback (most recent call last): ... AttributeError: 'ClassWithoutGetAttr' object has no attribute 'z'
Invocation from a class
----------------------- | 456 >>> getattr_hook(cwo, 'x') 123 >>> getattr_hook(cwo, 'y') 456 >>> getattr_hook(cwo, 'z') Traceback (most recent call last): ... AttributeError: 'ClassWithoutGetAttr' object has no attribute 'z'
Invocation from a class
----------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9562ab7-6c9a-49a1-8264-9b8c1c3e5b37 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,615 | supabase-export-v2 | d60555210bcfe443 | @property def __annotations__(self): return self.f.__annotations__
The :func:`functools.update_wrapper` call adds a ``__wrapped__`` attribute
that refers to the underlying function. Also it carries forward
the attributes necessary to make the wrapper look like the wrapped
function, including :attr:`~function.__name__`,... | trusted_official_docs | CPython Docs | @property def __annotations__(self): return self.f.__annotations__
The :func:`functools.update_wrapper` call adds a ``__wrapped__`` attribute
that refers to the underlying function. Also it carries forward
the attributes necessary to make the wrapper look like the wrapped
function, including :attr:`~function.__name__`,... | @property def __annotations__(self): return self.f.__annotations__
The :func:`functools.update_wrapper` call adds a ``__wrapped__`` attribute
that refers to the underlying function. Also it carries forward
the attributes necessary to make the wrapper look like the wrapped
function, including :attr:`~function.__name__`,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9f228ff-8c04-4bb7-9e23-8c08efa83c06 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,317 | supabase-export-v2 | 6a56ca527f6d4fc7 | This example shows how a simple descriptor works, but it isn't very useful. For retrieving constants, normal attribute lookup would be better.
In the next section, we'll create something more useful, a dynamic lookup. | trusted_official_docs | CPython Docs | This example shows how a simple descriptor works, but it isn't very useful. For retrieving constants, normal attribute lookup would be better.
In the next section, we'll create something more useful, a dynamic lookup. | This example shows how a simple descriptor works, but it isn't very useful. For retrieving constants, normal attribute lookup would be better.
In the next section, we'll create something more useful, a dynamic lookup. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aba2acd6-55d2-4653-be2b-4448a8836d3d | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,699 | supabase-export-v2 | a482a541e3b9ddf1 | the preceding section is not # doctestable due to the hex memory address for the __init__ function >>> isinstance(vars(H)['x'], Member) True >>> isinstance(vars(H)['y'], Member) True
When instances are created, they have a ``slot_values`` list where the
attributes are stored: | trusted_official_docs | CPython Docs | the preceding section is not # doctestable due to the hex memory address for the __init__ function >>> isinstance(vars(H)['x'], Member) True >>> isinstance(vars(H)['y'], Member) True
When instances are created, they have a ``slot_values`` list where the
attributes are stored: | the preceding section is not # doctestable due to the hex memory address for the __init__ function >>> isinstance(vars(H)['x'], Member) True >>> isinstance(vars(H)['y'], Member) True
When instances are created, they have a ``slot_values`` list where the
attributes are stored: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ad40415d-67a8-4092-a060-6bd09e3a9110 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,370 | supabase-export-v2 | 716649fda059c3b8 | 10) INFO:root:Updating 'name' to 'Peter P' INFO:root:Updating 'age' to 10 >>> kate = Person('Catherine C', 20) INFO:root:Updating 'name' to 'Catherine C' INFO:root:Updating 'age' to 20
The two *Person* instances contain only the private names: | trusted_official_docs | CPython Docs | 10) INFO:root:Updating 'name' to 'Peter P' INFO:root:Updating 'age' to 10 >>> kate = Person('Catherine C', 20) INFO:root:Updating 'name' to 'Catherine C' INFO:root:Updating 'age' to 20
The two *Person* instances contain only the private names: | 10) INFO:root:Updating 'name' to 'Peter P' INFO:root:Updating 'age' to 10 >>> kate = Person('Catherine C', 20) INFO:root:Updating 'name' to 'Catherine C' INFO:root:Updating 'age' to 20
The two *Person* instances contain only the private names: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ae4d0c9d-cea0-4636-b9ed-1cfffe9c58b8 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,707 | supabase-export-v2 | 5e0914376e520bc3 | are not shown because this section # is already a bit lengthy. We still test that code here. >>> del h.x >>> hasattr(h, 'x') False
# Also test the code for uninitialized slots
>>> class HU(Object, metaclass=Type):
... slot_names = ['x', 'y']
... >>> hu = HU()
>>> hasattr(hu, 'x')
False
>>> hasattr(hu, 'y')
False | trusted_official_docs | CPython Docs | are not shown because this section # is already a bit lengthy. We still test that code here. >>> del h.x >>> hasattr(h, 'x') False
# Also test the code for uninitialized slots
>>> class HU(Object, metaclass=Type):
... slot_names = ['x', 'y']
... >>> hu = HU()
>>> hasattr(hu, 'x')
False
>>> hasattr(hu, 'y')
False | are not shown because this section # is already a bit lengthy. We still test that code here. >>> del h.x >>> hasattr(h, 'x') False
# Also test the code for uninitialized slots
>>> class HU(Object, metaclass=Type):
... slot_names = ['x', 'y']
... >>> hu = HU()
>>> hasattr(hu, 'x')
False
>>> hasattr(hu, 'y')
False | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b549847b-e53f-4a96-a006-69e7e2e60a22 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,632 | supabase-export-v2 | 415048729cc15400 | class Dict(dict): @classmethod def fromkeys(cls, iterable, value=None): "Emulate dict_fromkeys() in Objects/dictobject.c" d = cls() for key in iterable: d[key] = value return d
Now a new dictionary of unique keys can be constructed like this: | trusted_official_docs | CPython Docs | class Dict(dict): @classmethod def fromkeys(cls, iterable, value=None): "Emulate dict_fromkeys() in Objects/dictobject.c" d = cls() for key in iterable: d[key] = value return d
Now a new dictionary of unique keys can be constructed like this: | class Dict(dict): @classmethod def fromkeys(cls, iterable, value=None): "Emulate dict_fromkeys() in Objects/dictobject.c" d = cls() for key in iterable: d[key] = value return d
Now a new dictionary of unique keys can be constructed like this: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b6e00501-999d-4b8d-9a60-aad9879227ce | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,678 | supabase-export-v2 | b1418e199f86e752 | def __set__(self, obj, value): 'Emulate member_set() in Objects/descrobject.c' obj._slotvalues[self.offset] = value
def __delete__(self, obj):
'Emulate member_delete() in Objects/descrobject.c'
value = obj._slotvalues[self.offset]
if value is null:
raise AttributeError(self.name)
obj._slotvalues[self.offset] = nul... | trusted_official_docs | CPython Docs | def __set__(self, obj, value): 'Emulate member_set() in Objects/descrobject.c' obj._slotvalues[self.offset] = value
def __delete__(self, obj):
'Emulate member_delete() in Objects/descrobject.c'
value = obj._slotvalues[self.offset]
if value is null:
raise AttributeError(self.name)
obj._slotvalues[self.offset] = nul... | def __set__(self, obj, value): 'Emulate member_set() in Objects/descrobject.c' obj._slotvalues[self.offset] = value
def __delete__(self, obj):
'Emulate member_delete() in Objects/descrobject.c'
value = obj._slotvalues[self.offset]
if value is null:
raise AttributeError(self.name)
obj._slotvalues[self.offset] = nul... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b765e02f-efed-43a8-90eb-4903877f387c | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,553 | supabase-export-v2 | 0ee1e543c6f3e9a1 | >>> cc = CC() >>> hasattr(cc, 'x') False >>> cc.x = 33 >>> cc.x 33 >>> del cc.x >>> hasattr(cc, 'x') False
>>> ccc = CCC()
>>> hasattr(ccc, 'x')
False
>>> ccc.x = 333
>>> ccc.x == 333
True
>>> del ccc.x
>>> hasattr(ccc, 'x')
False | trusted_official_docs | CPython Docs | >>> cc = CC() >>> hasattr(cc, 'x') False >>> cc.x = 33 >>> cc.x 33 >>> del cc.x >>> hasattr(cc, 'x') False
>>> ccc = CCC()
>>> hasattr(ccc, 'x')
False
>>> ccc.x = 333
>>> ccc.x == 333
True
>>> del ccc.x
>>> hasattr(ccc, 'x')
False | >>> cc = CC() >>> hasattr(cc, 'x') False >>> cc.x = 33 >>> cc.x 33 >>> del cc.x >>> hasattr(cc, 'x') False
>>> ccc = CCC()
>>> hasattr(ccc, 'x')
False
>>> ccc.x = 333
>>> ccc.x == 333
True
>>> del ccc.x
>>> hasattr(ccc, 'x')
False | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7efeefa-9e15-46ef-942a-fca4c9cced0f | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,426 | supabase-export-v2 | 764f9c9d5f5ac0f8 | protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`, and :meth:`~object.__delete__`. If any of those methods are defined for an attribute, it is said to be a :term:`descriptor`.
The default behavior for attribute access is to get, set, or delete the
attribute from an object's dictionary. For in... | trusted_official_docs | CPython Docs | protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`, and :meth:`~object.__delete__`. If any of those methods are defined for an attribute, it is said to be a :term:`descriptor`.
The default behavior for attribute access is to get, set, or delete the
attribute from an object's dictionary. For in... | protocol. Those methods are :meth:`~object.__get__`, :meth:`~object.__set__`, and :meth:`~object.__delete__`. If any of those methods are defined for an attribute, it is said to be a :term:`descriptor`.
The default behavior for attribute access is to get, set, or delete the
attribute from an object's dictionary. For in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b838f2ca-dd61-4759-ab4a-91d27e939664 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,376 | supabase-export-v2 | 73945cea51b7180a | created or the name of class variable it was assigned to. (This method, if present, is called even if the class is not a descriptor.)
Descriptors get invoked by the dot operator during attribute lookup. If a
descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``,
the descriptor instance is returne... | trusted_official_docs | CPython Docs | created or the name of class variable it was assigned to. (This method, if present, is called even if the class is not a descriptor.)
Descriptors get invoked by the dot operator during attribute lookup. If a
descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``,
the descriptor instance is returne... | created or the name of class variable it was assigned to. (This method, if present, is called even if the class is not a descriptor.)
Descriptors get invoked by the dot operator during attribute lookup. If a
descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``,
the descriptor instance is returne... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b9a028c5-abae-4501-9c7a-62eddb675786 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,492 | supabase-export-v2 | 4cb78171f8652d78 | * Overriding :meth:`~object.__getattribute__` prevents automatic descriptor calls because all the descriptor logic is in that method.
* :meth:`!object.__getattribute__` and :meth:`!type.__getattribute__` make
different calls to :meth:`~object.__get__`. The first includes the instance and may
include the class. The se... | trusted_official_docs | CPython Docs | * Overriding :meth:`~object.__getattribute__` prevents automatic descriptor calls because all the descriptor logic is in that method.
* :meth:`!object.__getattribute__` and :meth:`!type.__getattribute__` make
different calls to :meth:`~object.__get__`. The first includes the instance and may
include the class. The se... | * Overriding :meth:`~object.__getattribute__` prevents automatic descriptor calls because all the descriptor logic is in that method.
* :meth:`!object.__getattribute__` and :meth:`!type.__getattribute__` make
different calls to :meth:`~object.__get__`. The first includes the instance and may
include the class. The se... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b9f88fb0-bd4f-49fe-9f6e-77b965d29fe0 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,670 | supabase-export-v2 | d2766db93b046a49 | class CP: __slots__ = () # Eliminates the instance dict
@cached_property # Requires an instance dict
def pi(self):
return 4 * sum((-1.0)**n / (2.0*n + 1.0)
for n in reversed(range(100_000))) | trusted_official_docs | CPython Docs | class CP: __slots__ = () # Eliminates the instance dict
@cached_property # Requires an instance dict
def pi(self):
return 4 * sum((-1.0)**n / (2.0*n + 1.0)
for n in reversed(range(100_000))) | class CP: __slots__ = () # Eliminates the instance dict
@cached_property # Requires an instance dict
def pi(self):
return 4 * sum((-1.0)**n / (2.0*n + 1.0)
for n in reversed(range(100_000))) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
baecf222-0530-4157-8a72-e96970256a25 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,439 | supabase-export-v2 | 4ff2cfe7a87264ac | But it is more common for a descriptor to be invoked automatically from attribute access.
The expression ``obj.x`` looks up the attribute ``x`` in the chain of
namespaces for ``obj``. If the search finds a descriptor outside of the
instance :attr:`~object.__dict__`, its :meth:`~object.__get__` method is
invoked accordi... | trusted_official_docs | CPython Docs | But it is more common for a descriptor to be invoked automatically from attribute access.
The expression ``obj.x`` looks up the attribute ``x`` in the chain of
namespaces for ``obj``. If the search finds a descriptor outside of the
instance :attr:`~object.__dict__`, its :meth:`~object.__get__` method is
invoked accordi... | But it is more common for a descriptor to be invoked automatically from attribute access.
The expression ``obj.x`` looks up the attribute ``x`` in the chain of
namespaces for ``obj``. If the search finds a descriptor outside of the
instance :attr:`~object.__dict__`, its :meth:`~object.__get__` method is
invoked accordi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bdae77bd-154c-40de-8cb4-f2cd9625f5d3 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,329 | supabase-export-v2 | 05197b27cd5ab316 | Managed attributes ------------------
A popular use for descriptors is managing access to instance data. The
descriptor is assigned to a public attribute in the class dictionary while the
actual data is stored as a private attribute in the instance dictionary. The
descriptor's :meth:`~object.__get__` and :meth:`~object... | trusted_official_docs | CPython Docs | Managed attributes ------------------
A popular use for descriptors is managing access to instance data. The
descriptor is assigned to a public attribute in the class dictionary while the
actual data is stored as a private attribute in the instance dictionary. The
descriptor's :meth:`~object.__get__` and :meth:`~object... | Managed attributes ------------------
A popular use for descriptors is managing access to instance data. The
descriptor is assigned to a public attribute in the class dictionary while the
actual data is stored as a private attribute in the instance dictionary. The
descriptor's :meth:`~object.__get__` and :meth:`~object... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bdc88328-0e60-4b2b-8d35-cb6106c8da4a | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,447 | supabase-export-v2 | a395513f6fb23ad3 | def find_name_in_mro(cls, name, default): "Emulate _PyType_Lookup() in Objects/typeobject.c" for base in cls.__mro__: if name in vars(base): return vars(base)[name] return default
def object_getattribute(obj, name):
"Emulate PyObject_GenericGetAttr() in Objects/object.c"
null = sentinel('null')
objtype = type(obj)
... | trusted_official_docs | CPython Docs | def find_name_in_mro(cls, name, default): "Emulate _PyType_Lookup() in Objects/typeobject.c" for base in cls.__mro__: if name in vars(base): return vars(base)[name] return default
def object_getattribute(obj, name):
"Emulate PyObject_GenericGetAttr() in Objects/object.c"
null = sentinel('null')
objtype = type(obj)
... | def find_name_in_mro(cls, name, default): "Emulate _PyType_Lookup() in Objects/typeobject.c" for base in cls.__mro__: if name in vars(base): return vars(base)[name] return default
def object_getattribute(obj, name):
"Emulate PyObject_GenericGetAttr() in Objects/object.c"
null = sentinel('null')
objtype = type(obj)
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bdd13006-8a45-4094-a12f-628dd0c05eae | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,427 | supabase-export-v2 | aa22610935030c9d | may override the default behavior and invoke the descriptor method instead. Where this occurs in the precedence chain depends on which descriptor methods were defined.
Descriptors are a powerful, general purpose protocol. They are the mechanism
behind properties, methods, static methods, class methods, and
:func:`super... | trusted_official_docs | CPython Docs | may override the default behavior and invoke the descriptor method instead. Where this occurs in the precedence chain depends on which descriptor methods were defined.
Descriptors are a powerful, general purpose protocol. They are the mechanism
behind properties, methods, static methods, class methods, and
:func:`super... | may override the default behavior and invoke the descriptor method instead. Where this occurs in the precedence chain depends on which descriptor methods were defined.
Descriptors are a powerful, general purpose protocol. They are the mechanism
behind properties, methods, static methods, class methods, and
:func:`super... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
be80ab51-07fa-4a8e-9e09-38dd7c97bde8 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,384 | supabase-export-v2 | 125253b2629bcc47 | Validator class ---------------
A validator is a descriptor for managed attribute access. Prior to storing
any data, it verifies that the new value meets various type and range
restrictions. If those restrictions aren't met, it raises an exception to
prevent data corruption at its source. | trusted_official_docs | CPython Docs | Validator class ---------------
A validator is a descriptor for managed attribute access. Prior to storing
any data, it verifies that the new value meets various type and range
restrictions. If those restrictions aren't met, it raises an exception to
prevent data corruption at its source. | Validator class ---------------
A validator is a descriptor for managed attribute access. Prior to storing
any data, it verifies that the new value meets various type and range
restrictions. If those restrictions aren't met, it raises an exception to
prevent data corruption at its source. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c04bc187-1712-49a2-ae3a-dbbad4ec9083 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,684 | supabase-export-v2 | 0f34a63f84c94354 | calls PyTypeReady() which calls add_methods() slot_names = mapping.get('slot_names', []) for offset, name in enumerate(slot_names): mapping[name] = Member(name, clsname, offset) return type.__new__(mcls, clsname, bases, mapping, **kwargs)
The :meth:`object.__new__` method takes care of creating instances that have
slot... | trusted_official_docs | CPython Docs | calls PyTypeReady() which calls add_methods() slot_names = mapping.get('slot_names', []) for offset, name in enumerate(slot_names): mapping[name] = Member(name, clsname, offset) return type.__new__(mcls, clsname, bases, mapping, **kwargs)
The :meth:`object.__new__` method takes care of creating instances that have
slot... | calls PyTypeReady() which calls add_methods() slot_names = mapping.get('slot_names', []) for offset, name in enumerate(slot_names): mapping[name] = Member(name, clsname, offset) return type.__new__(mcls, clsname, bases, mapping, **kwargs)
The :meth:`object.__new__` method takes care of creating instances that have
slot... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c06096af-6d67-4a57-b48d-2c3613f5e230 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,435 | supabase-export-v2 | e343e68156b59b25 | the data descriptor takes precedence. If an instance's dictionary has an entry with the same name as a non-data descriptor, the dictionary entry takes precedence.
To make a read-only data descriptor, define both :meth:`~object.__get__` and
:meth:`~object.__set__` with the :meth:`~object.__set__` raising an :exc:`Attrib... | trusted_official_docs | CPython Docs | the data descriptor takes precedence. If an instance's dictionary has an entry with the same name as a non-data descriptor, the dictionary entry takes precedence.
To make a read-only data descriptor, define both :meth:`~object.__get__` and
:meth:`~object.__set__` with the :meth:`~object.__set__` raising an :exc:`Attrib... | the data descriptor takes precedence. If an instance's dictionary has an entry with the same name as a non-data descriptor, the dictionary entry takes precedence.
To make a read-only data descriptor, define both :meth:`~object.__get__` and
:meth:`~object.__set__` with the :meth:`~object.__set__` raising an :exc:`Attrib... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c673776a-7c98-4bbe-ac9d-e9071fa74546 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,622 | supabase-export-v2 | e30464d3fd98da20 | {'x': <class 'int'>, 'return': <class 'str'>} >>> f.__annotations__ {'x': <class 'int'>, 'return': <class 'str'>} >>> sm.__module__ == f.__module__ True >>> sm(3) '!!!' >>> f(3) '!!!'
>>> wrapped_ord('A')
65
>>> wrapped_ord.__module__ == ord.__module__
True
>>> wrapped_ord.__wrapped__ == ord
True
>>> wrapped_ord.... | trusted_official_docs | CPython Docs | {'x': <class 'int'>, 'return': <class 'str'>} >>> f.__annotations__ {'x': <class 'int'>, 'return': <class 'str'>} >>> sm.__module__ == f.__module__ True >>> sm(3) '!!!' >>> f(3) '!!!'
>>> wrapped_ord('A')
65
>>> wrapped_ord.__module__ == ord.__module__
True
>>> wrapped_ord.__wrapped__ == ord
True
>>> wrapped_ord.... | {'x': <class 'int'>, 'return': <class 'str'>} >>> f.__annotations__ {'x': <class 'int'>, 'return': <class 'str'>} >>> sm.__module__ == f.__module__ True >>> sm(3) '!!!' >>> f(3) '!!!'
>>> wrapped_ord('A')
65
>>> wrapped_ord.__module__ == ord.__module__
True
>>> wrapped_ord.__wrapped__ == ord
True
>>> wrapped_ord.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c76c4985-22c5-466d-bc87-8e0f8d522ac7 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,471 | supabase-export-v2 | 3abead4ae1ffd538 | >>> u2 = U2() >>> object_getattribute(u2, 'x') == u2.x == (D1, u2, U2) True
Note, there is no :meth:`~object.__getattr__` hook in the :meth:`~object.__getattribute__`
code. That is why calling :meth:`~object.__getattribute__` directly or with
``super().__getattribute__`` will bypass :meth:`~object.__getattr__` entirely... | trusted_official_docs | CPython Docs | >>> u2 = U2() >>> object_getattribute(u2, 'x') == u2.x == (D1, u2, U2) True
Note, there is no :meth:`~object.__getattr__` hook in the :meth:`~object.__getattribute__`
code. That is why calling :meth:`~object.__getattribute__` directly or with
``super().__getattribute__`` will bypass :meth:`~object.__getattr__` entirely... | >>> u2 = U2() >>> object_getattribute(u2, 'x') == u2.x == (D1, u2, U2) True
Note, there is no :meth:`~object.__getattr__` hook in the :meth:`~object.__getattribute__`
code. That is why calling :meth:`~object.__getattribute__` directly or with
``super().__getattribute__`` will bypass :meth:`~object.__getattr__` entirely... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
caba2ab8-e3f1-4126-a8c5-65473a836d78 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,300 | supabase-export-v2 | 241c77fda63c7801 | 2) The second section shows a complete, practical descriptor example. If you already know the basics, start there.
3) The third section provides a more technical tutorial that goes into the
detailed mechanics of how descriptors work. Most people don't need this
level of detail. | trusted_official_docs | CPython Docs | 2) The second section shows a complete, practical descriptor example. If you already know the basics, start there.
3) The third section provides a more technical tutorial that goes into the
detailed mechanics of how descriptors work. Most people don't need this
level of detail. | 2) The second section shows a complete, practical descriptor example. If you already know the basics, start there.
3) The third section provides a more technical tutorial that goes into the
detailed mechanics of how descriptors work. Most people don't need this
level of detail. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ce9aa4cd-a250-4d15-8a90-cf5ba70814bc | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,663 | supabase-export-v2 | 3df920ec08301a49 | .. doctest::
>>> mark = Immutable('Botany', 'Mark Watney')
>>> mark.dept
'Botany'
>>> mark.dept = 'Space Pirate'
Traceback (most recent call last):
... AttributeError: property 'dept' of 'Immutable' object has no setter
>>> mark.location = 'Mars'
Traceback (most recent call last):
... AttributeError: 'Immutable... | trusted_official_docs | CPython Docs | .. doctest::
>>> mark = Immutable('Botany', 'Mark Watney')
>>> mark.dept
'Botany'
>>> mark.dept = 'Space Pirate'
Traceback (most recent call last):
... AttributeError: property 'dept' of 'Immutable' object has no setter
>>> mark.location = 'Mars'
Traceback (most recent call last):
... AttributeError: 'Immutable... | .. doctest::
>>> mark = Immutable('Botany', 'Mark Watney')
>>> mark.dept
'Botany'
>>> mark.dept = 'Space Pirate'
Traceback (most recent call last):
... AttributeError: property 'dept' of 'Immutable' object has no setter
>>> mark.location = 'Mars'
Traceback (most recent call last):
... AttributeError: 'Immutable... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d75e809e-dd02-49d6-9ce1-cb233efaf0b1 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,434 | supabase-export-v2 | 3c023a4d8bbf5715 | is considered a data descriptor. Descriptors that only define :meth:`~object.__get__` are called non-data descriptors (they are often used for methods but other uses are possible).
Data and non-data descriptors differ in how overrides are calculated with
respect to entries in an instance's dictionary. If an instance's ... | trusted_official_docs | CPython Docs | is considered a data descriptor. Descriptors that only define :meth:`~object.__get__` are called non-data descriptors (they are often used for methods but other uses are possible).
Data and non-data descriptors differ in how overrides are calculated with
respect to entries in an instance's dictionary. If an instance's ... | is considered a data descriptor. Descriptors that only define :meth:`~object.__get__` are called non-data descriptors (they are often used for methods but other uses are possible).
Data and non-data descriptors differ in how overrides are calculated with
respect to entries in an instance's dictionary. If an instance's ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d834537e-ecca-45e2-9a97-b35476575bb5 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,378 | supabase-export-v2 | 9f58422409158827 | Descriptors only work when used as class variables. When put in instances, they have no effect.
The main motivation for descriptors is to provide a hook allowing objects
stored in class variables to control what happens during attribute lookup. | trusted_official_docs | CPython Docs | Descriptors only work when used as class variables. When put in instances, they have no effect.
The main motivation for descriptors is to provide a hook allowing objects
stored in class variables to control what happens during attribute lookup. | Descriptors only work when used as class variables. When put in instances, they have no effect.
The main motivation for descriptors is to provide a hook allowing objects
stored in class variables to control what happens during attribute lookup. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d8a2da65-8185-4308-9058-1fcf42b08804 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,377 | supabase-export-v2 | 586bdb82a8cf68bd | get invoked by the dot operator during attribute lookup. If a descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``, the descriptor instance is returned without invoking it.
Descriptors only work when used as class variables. When put in instances,
they have no effect. | trusted_official_docs | CPython Docs | get invoked by the dot operator during attribute lookup. If a descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``, the descriptor instance is returned without invoking it.
Descriptors only work when used as class variables. When put in instances,
they have no effect. | get invoked by the dot operator during attribute lookup. If a descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``, the descriptor instance is returned without invoking it.
Descriptors only work when used as class variables. When put in instances,
they have no effect. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dc12d94f-983b-4bb0-9ea8-970cc738d81a | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,559 | supabase-export-v2 | 7ba6802f9d11d532 | The :func:`property` builtin helps whenever a user interface has granted attribute access and then subsequent changes require the intervention of a method.
For instance, a spreadsheet class may grant access to a cell value through
``Cell('b10').value``. Subsequent improvements to the program require the cell
to be reca... | trusted_official_docs | CPython Docs | The :func:`property` builtin helps whenever a user interface has granted attribute access and then subsequent changes require the intervention of a method.
For instance, a spreadsheet class may grant access to a cell value through
``Cell('b10').value``. Subsequent improvements to the program require the cell
to be reca... | The :func:`property` builtin helps whenever a user interface has granted attribute access and then subsequent changes require the intervention of a method.
For instance, a spreadsheet class may grant access to a cell value through
``Cell('b10').value``. Subsequent improvements to the program require the cell
to be reca... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e12c29a2-2fd0-4f8b-bd60-87c52d8cbb00 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,449 | supabase-export-v2 | 0f15b1b6c670cf64 | .. testcode:: :hide:
# Test the fidelity of object_getattribute() by comparing it with the
# normal object.__getattribute__(). The former will be accessed by
# square brackets and the latter by the dot operator. | trusted_official_docs | CPython Docs | .. testcode:: :hide:
# Test the fidelity of object_getattribute() by comparing it with the
# normal object.__getattribute__(). The former will be accessed by
# square brackets and the latter by the dot operator. | .. testcode:: :hide:
# Test the fidelity of object_getattribute() by comparing it with the
# normal object.__getattribute__(). The former will be accessed by
# square brackets and the latter by the dot operator. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e2e21163-eb80-42e0-ae60-5f7facb3593a | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,397 | supabase-export-v2 | 45f08adbf1c12862 | 2) :class:`!Number` verifies that a value is either an :class:`int` or :class:`float`. Optionally, it verifies that a value is between a given minimum or maximum.
3) :class:`!String` verifies that a value is a :class:`str`. Optionally, it
validates a given minimum or maximum length. It can validate a
user-defined `pr... | trusted_official_docs | CPython Docs | 2) :class:`!Number` verifies that a value is either an :class:`int` or :class:`float`. Optionally, it verifies that a value is between a given minimum or maximum.
3) :class:`!String` verifies that a value is a :class:`str`. Optionally, it
validates a given minimum or maximum length. It can validate a
user-defined `pr... | 2) :class:`!Number` verifies that a value is either an :class:`int` or :class:`float`. Optionally, it verifies that a value is between a given minimum or maximum.
3) :class:`!String` verifies that a value is a :class:`str`. Optionally, it
validates a given minimum or maximum length. It can validate a
user-defined `pr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e7777b9d-e832-460b-936b-8e9a8510487d | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,554 | supabase-export-v2 | c233c374e5cdcf59 | >>> ccc = CCC() >>> hasattr(ccc, 'x') False >>> ccc.x = 333 >>> ccc.x == 333 True >>> del ccc.x >>> hasattr(ccc, 'x') False
>>> cc = CC()
>>> cc.x = 33
>>> try:
... cc.no_getter
... except AttributeError as e:
... type(e).__name__
... 'AttributeError' | trusted_official_docs | CPython Docs | >>> ccc = CCC() >>> hasattr(ccc, 'x') False >>> ccc.x = 333 >>> ccc.x == 333 True >>> del ccc.x >>> hasattr(ccc, 'x') False
>>> cc = CC()
>>> cc.x = 33
>>> try:
... cc.no_getter
... except AttributeError as e:
... type(e).__name__
... 'AttributeError' | >>> ccc = CCC() >>> hasattr(ccc, 'x') False >>> ccc.x = 333 >>> ccc.x == 333 True >>> del ccc.x >>> hasattr(ccc, 'x') False
>>> cc = CC()
>>> cc.x = 33
>>> try:
... cc.no_getter
... except AttributeError as e:
... type(e).__name__
... 'AttributeError' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eb2bb3c4-553a-4eac-9abb-0e084a4cbe5e | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,314 | supabase-export-v2 | 7800ee1db5555820 | >>> a = A() # Make an instance of class A >>> a.x # Normal attribute lookup 5 >>> a.y # Descriptor lookup 10
In the ``a.x`` attribute lookup, the dot operator finds ``'x': 5``
in the class dictionary. In the ``a.y`` lookup, the dot operator
finds a descriptor instance, recognized by its ``__get__`` method. Calling that... | trusted_official_docs | CPython Docs | >>> a = A() # Make an instance of class A >>> a.x # Normal attribute lookup 5 >>> a.y # Descriptor lookup 10
In the ``a.x`` attribute lookup, the dot operator finds ``'x': 5``
in the class dictionary. In the ``a.y`` lookup, the dot operator
finds a descriptor instance, recognized by its ``__get__`` method. Calling that... | >>> a = A() # Make an instance of class A >>> a.x # Normal attribute lookup 5 >>> a.y # Descriptor lookup 10
In the ``a.x`` attribute lookup, the dot operator finds ``'x': 5``
in the class dictionary. In the ``a.y`` lookup, the dot operator
finds a descriptor instance, recognized by its ``__get__`` method. Calling that... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed17e5cb-518d-42ec-be46-459a0a6d7d0f | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,418 | supabase-export-v2 | 6693e3c93970959e | >>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number Traceback (most recent call last): ... TypeError: Expected 'V' to be an int or float
>>> c = Component('WIDGET', 'metal', 5) # Allowed: The inputs are valid | trusted_official_docs | CPython Docs | >>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number Traceback (most recent call last): ... TypeError: Expected 'V' to be an int or float
>>> c = Component('WIDGET', 'metal', 5) # Allowed: The inputs are valid | >>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number Traceback (most recent call last): ... TypeError: Expected 'V' to be an int or float
>>> c = Component('WIDGET', 'metal', 5) # Allowed: The inputs are valid | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed61ff10-975c-47c5-81e3-f256ac18d803 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,415 | supabase-export-v2 | c855c760b5b47e25 | # Blocked: 'Widget' is not all uppercase Traceback (most recent call last): ... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget'
>>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled
Traceback (most recent call last):
... ValueError: Expected 'metle' to be one of {'metal... | trusted_official_docs | CPython Docs | # Blocked: 'Widget' is not all uppercase Traceback (most recent call last): ... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget'
>>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled
Traceback (most recent call last):
... ValueError: Expected 'metle' to be one of {'metal... | # Blocked: 'Widget' is not all uppercase Traceback (most recent call last): ... ValueError: Expected <method 'isupper' of 'str' objects> to be true for 'Widget'
>>> Component('WIDGET', 'metle', 5) # Blocked: 'metle' is misspelled
Traceback (most recent call last):
... ValueError: Expected 'metle' to be one of {'metal... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ee149329-2f77-470c-ac3e-fcbf91fe81bb | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,565 | supabase-export-v2 | 0b1f49617f286d53 | Python's object oriented features are built upon a function based environment. Using non-data descriptors, the two are merged seamlessly.
Functions stored in class dictionaries get turned into methods when invoked. Methods only differ from regular functions in that the object instance is
prepended to the other argument... | trusted_official_docs | CPython Docs | Python's object oriented features are built upon a function based environment. Using non-data descriptors, the two are merged seamlessly.
Functions stored in class dictionaries get turned into methods when invoked. Methods only differ from regular functions in that the object instance is
prepended to the other argument... | Python's object oriented features are built upon a function based environment. Using non-data descriptors, the two are merged seamlessly.
Functions stored in class dictionaries get turned into methods when invoked. Methods only differ from regular functions in that the object instance is
prepended to the other argument... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ee1f7d0a-d7d1-410b-b736-df5d03f46ac2 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,676 | supabase-export-v2 | 99f1f4e1995a6b6e | def __init__(self, name, clsname, offset): 'Emulate PyMemberDef in Include/descrobject.h' # Also see descr_new() in Objects/descrobject.c self.name = name self.clsname = clsname self.offset = offset
def __get__(self, obj, objtype=None):
'Emulate member_get() in Objects/descrobject.c'
# Also see PyMember_GetOne() in P... | trusted_official_docs | CPython Docs | def __init__(self, name, clsname, offset): 'Emulate PyMemberDef in Include/descrobject.h' # Also see descr_new() in Objects/descrobject.c self.name = name self.clsname = clsname self.offset = offset
def __get__(self, obj, objtype=None):
'Emulate member_get() in Objects/descrobject.c'
# Also see PyMember_GetOne() in P... | def __init__(self, name, clsname, offset): 'Emulate PyMemberDef in Include/descrobject.h' # Also see descr_new() in Objects/descrobject.c self.name = name self.clsname = clsname self.offset = offset
def __get__(self, obj, objtype=None):
'Emulate member_get() in Objects/descrobject.c'
# Also see PyMember_GetOne() in P... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f1bf650f-78d5-414b-852d-334afafab7be | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,340 | supabase-export-v2 | 21167cf75b95d3c9 | def birthday(self): self.age += 1 # Calls both __get__() and __set__()
An interactive session shows that all access to the managed attribute *age* is
logged, but that the regular attribute *name* is not logged: | trusted_official_docs | CPython Docs | def birthday(self): self.age += 1 # Calls both __get__() and __set__()
An interactive session shows that all access to the managed attribute *age* is
logged, but that the regular attribute *name* is not logged: | def birthday(self): self.age += 1 # Calls both __get__() and __set__()
An interactive session shows that all access to the managed attribute *age* is
logged, but that the regular attribute *name* is not logged: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f5aa7b1f-3747-406d-92d1-ddf2a831bfa4 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,498 | supabase-export-v2 | e4c2789e01ed674b | The implementation details are in :c:func:`!type_new` and :c:func:`!set_names` in :source:`Objects/typeobject.c`.
Since the update logic is in :meth:`!type.__new__`, notifications only take
place at the time of class creation. If descriptors are added to the class
afterwards, :meth:`~object.__set_name__` will need to b... | trusted_official_docs | CPython Docs | The implementation details are in :c:func:`!type_new` and :c:func:`!set_names` in :source:`Objects/typeobject.c`.
Since the update logic is in :meth:`!type.__new__`, notifications only take
place at the time of class creation. If descriptors are added to the class
afterwards, :meth:`~object.__set_name__` will need to b... | The implementation details are in :c:func:`!type_new` and :c:func:`!set_names` in :source:`Objects/typeobject.c`.
Since the update logic is in :meth:`!type.__new__`, notifications only take
place at the time of class creation. If descriptors are added to the class
afterwards, :meth:`~object.__set_name__` will need to b... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f60fe48d-f31c-480b-8dcd-372ee472d784 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,706 | supabase-export-v2 | a1ecf968f9c3826b | .. doctest:: :hide:
# Examples for deleted attributes are not shown because this section
# is already a bit lengthy. We still test that code here. >>> del h.x
>>> hasattr(h, 'x')
False | trusted_official_docs | CPython Docs | .. doctest:: :hide:
# Examples for deleted attributes are not shown because this section
# is already a bit lengthy. We still test that code here. >>> del h.x
>>> hasattr(h, 'x')
False | .. doctest:: :hide:
# Examples for deleted attributes are not shown because this section
# is already a bit lengthy. We still test that code here. >>> del h.x
>>> hasattr(h, 'x')
False | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f7f50979-97ae-4744-8fa0-6eae145da1c3 | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,375 | supabase-export-v2 | 6b0f976fc560ecfe | A :term:`descriptor` is what we call any object that defines :meth:`~object.__get__`, :meth:`~object.__set__`, or :meth:`~object.__delete__`.
Optionally, descriptors can have a :meth:`~object.__set_name__` method. This is only
used in cases where a descriptor needs to know either the class where it was
created or the n... | trusted_official_docs | CPython Docs | A :term:`descriptor` is what we call any object that defines :meth:`~object.__get__`, :meth:`~object.__set__`, or :meth:`~object.__delete__`.
Optionally, descriptors can have a :meth:`~object.__set_name__` method. This is only
used in cases where a descriptor needs to know either the class where it was
created or the n... | A :term:`descriptor` is what we call any object that defines :meth:`~object.__get__`, :meth:`~object.__set__`, or :meth:`~object.__delete__`.
Optionally, descriptors can have a :meth:`~object.__set_name__` method. This is only
used in cases where a descriptor needs to know either the class where it was
created or the n... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f8a9d32e-94f0-4bd4-91ef-b88011d169db | CPython Docs | file://datasets/cpython/Doc/howto/descriptor.rst | unknown | 648a56dc-df5a-4761-a637-03ab957df2ef | 58,548 | supabase-export-v2 | 650b00a91968356a | # Verify the Property() emulation
class CC:
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = Property(getx, setx, delx, "I'm the 'x' property.")
no_getter = Property(None, setx, delx, "I'm the 'x' property.")
no_setter = Property(getx, None, delx, "I'm th... | trusted_official_docs | CPython Docs | # Verify the Property() emulation
class CC:
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = Property(getx, setx, delx, "I'm the 'x' property.")
no_getter = Property(None, setx, delx, "I'm the 'x' property.")
no_setter = Property(getx, None, delx, "I'm th... | # Verify the Property() emulation
class CC:
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = Property(getx, setx, delx, "I'm the 'x' property.")
no_getter = Property(None, setx, delx, "I'm the 'x' property.")
no_setter = Property(getx, None, delx, "I'm th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0341e3a7-c1c8-49d2-8931-129337855b39 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,767 | supabase-export-v2 | c49f32bdac30767a | of it. For example, if an extension type has an internal count field, you could use a critical section while reading or writing that field::
// read the count, returns new reference to internal count value
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(obj);
result = Py_NewRef(obj->count);
Py_END_CRITICAL_SECTION();
... | trusted_official_docs | CPython Docs | of it. For example, if an extension type has an internal count field, you could use a critical section while reading or writing that field::
// read the count, returns new reference to internal count value
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(obj);
result = Py_NewRef(obj->count);
Py_END_CRITICAL_SECTION();
... | of it. For example, if an extension type has an internal count field, you could use a critical section while reading or writing that field::
// read the count, returns new reference to internal count value
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(obj);
result = Py_NewRef(obj->count);
Py_END_CRITICAL_SECTION();
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0b47720f-b617-459e-81ca-d0bfda542d34 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,798 | supabase-export-v2 | b13a521f06311d40 | C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix.
* `pypa/manylinux <https://github.com/pypa/manylinux>`_ supports the
free-threaded build, with the ``t`` suffix, such as ``python3.14t``. * `pypa/cibuildwheel <https:/... | trusted_official_docs | CPython Docs | C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix.
* `pypa/manylinux <https://github.com/pypa/manylinux>`_ supports the
free-threaded build, with the ``t`` suffix, such as ``python3.14t``. * `pypa/cibuildwheel <https:/... | C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix.
* `pypa/manylinux <https://github.com/pypa/manylinux>`_ supports the
free-threaded build, with the ``t`` suffix, such as ``python3.14t``. * `pypa/cibuildwheel <https:/... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0bef55c0-016e-48c3-8202-81acf6dd7a49 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,795 | supabase-export-v2 | 2c862a32e2a11500 | if your own code never uses critical sections on a particular object type, **CPython internals may use the critical section API on any Python object**.
If your extension type needs its own lock, add a separate :c:type:`PyMutex`
field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is ver... | trusted_official_docs | CPython Docs | if your own code never uses critical sections on a particular object type, **CPython internals may use the critical section API on any Python object**.
If your extension type needs its own lock, add a separate :c:type:`PyMutex`
field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is ver... | if your own code never uses critical sections on a particular object type, **CPython internals may use the critical section API on any Python object**.
If your extension type needs its own lock, add a separate :c:type:`PyMutex`
field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is ver... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e483be1-c4a8-490a-84ac-76660f1917a6 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,718 | supabase-export-v2 | c5a37c71d4e76520 | to explicitly indicate that they support running with the GIL disabled; otherwise importing the extension will raise a warning and enable the GIL at runtime.
There are two ways to indicate that an extension module supports running with
the GIL disabled depending on whether the extension uses multi-phase or
single-phase... | trusted_official_docs | CPython Docs | to explicitly indicate that they support running with the GIL disabled; otherwise importing the extension will raise a warning and enable the GIL at runtime.
There are two ways to indicate that an extension module supports running with
the GIL disabled depending on whether the extension uses multi-phase or
single-phase... | to explicitly indicate that they support running with the GIL disabled; otherwise importing the extension will raise a warning and enable the GIL at runtime.
There are two ways to indicate that an extension module supports running with
the GIL disabled depending on whether the extension uses multi-phase or
single-phase... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
11dcd4a0-68fd-4bc3-9b81-f17471833932 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,724 | supabase-export-v2 | d48e163a482be500 | Single-Phase Initialization ...........................
Extensions that use legacy :ref:`single-phase initialization <single-phase-initialization>`
(that is, :c:func:`PyModule_Create`) should call :c:func:`PyUnstable_Module_SetGIL` to
indicate that they support running with the GIL disabled. The function is
only define... | trusted_official_docs | CPython Docs | Single-Phase Initialization ...........................
Extensions that use legacy :ref:`single-phase initialization <single-phase-initialization>`
(that is, :c:func:`PyModule_Create`) should call :c:func:`PyUnstable_Module_SetGIL` to
indicate that they support running with the GIL disabled. The function is
only define... | Single-Phase Initialization ...........................
Extensions that use legacy :ref:`single-phase initialization <single-phase-initialization>`
(that is, :c:func:`PyModule_Create`) should call :c:func:`PyUnstable_Module_SetGIL` to
indicate that they support running with the GIL disabled. The function is
only define... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
15e28f63-090d-4791-bdd6-fdba31d2013e | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,715 | supabase-export-v2 | 906a02062b554fbe | .. note::
On Windows, this macro is not defined automatically, but must be specified
to the compiler when building. The :func:`sysconfig.get_config_var` function
can be used to determine whether the current running interpreter had the
macro defined. | trusted_official_docs | CPython Docs | .. note::
On Windows, this macro is not defined automatically, but must be specified
to the compiler when building. The :func:`sysconfig.get_config_var` function
can be used to determine whether the current running interpreter had the
macro defined. | .. note::
On Windows, this macro is not defined automatically, but must be specified
to the compiler when building. The :func:`sysconfig.get_config_var` function
can be used to determine whether the current running interpreter had the
macro defined. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
174fe8d3-c3f0-4543-8028-440870604f5f | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,765 | supabase-export-v2 | 82f77c631619eedd | * :c:macro:`Py_BEGIN_CRITICAL_SECTION2` and :c:macro:`Py_END_CRITICAL_SECTION2` - For locking two objects simultaneously
These macros must be used in matching pairs and must appear in the same C
scope, since they establish a new local scope. These macros are no-ops in
non-free-threaded builds, so they can be safely add... | trusted_official_docs | CPython Docs | * :c:macro:`Py_BEGIN_CRITICAL_SECTION2` and :c:macro:`Py_END_CRITICAL_SECTION2` - For locking two objects simultaneously
These macros must be used in matching pairs and must appear in the same C
scope, since they establish a new local scope. These macros are no-ops in
non-free-threaded builds, so they can be safely add... | * :c:macro:`Py_BEGIN_CRITICAL_SECTION2` and :c:macro:`Py_END_CRITICAL_SECTION2` - For locking two objects simultaneously
These macros must be used in matching pairs and must appear in the same C
scope, since they establish a new local scope. These macros are no-ops in
non-free-threaded builds, so they can be safely add... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
18e82308-8ec8-4868-8a1a-eb7ca6795d83 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,786 | supabase-export-v2 | 9d9d3eb849191564 | * You can lock at most two objects simultaneously with these APIs. If you need to lock more objects, you'll need to restructure your code.
* While critical sections will not deadlock if you attempt to lock the same
object twice, they are less efficient than purpose-built reentrant locks for
this use case. | trusted_official_docs | CPython Docs | * You can lock at most two objects simultaneously with these APIs. If you need to lock more objects, you'll need to restructure your code.
* While critical sections will not deadlock if you attempt to lock the same
object twice, they are less efficient than purpose-built reentrant locks for
this use case. | * You can lock at most two objects simultaneously with these APIs. If you need to lock more objects, you'll need to restructure your code.
* While critical sections will not deadlock if you attempt to lock the same
object twice, they are less efficient than purpose-built reentrant locks for
this use case. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
191bc5d2-5a64-4bd3-9574-67a2bfe11996 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,774 | supabase-export-v2 | f1f9c301ae313468 | sections follow a stack discipline within each thread (the "begin" and "end" macros enforce this since they must be paired and within the same scope)
* Critical sections automatically release and reacquire locks around potential
blocking operations | trusted_official_docs | CPython Docs | sections follow a stack discipline within each thread (the "begin" and "end" macros enforce this since they must be paired and within the same scope)
* Critical sections automatically release and reacquire locks around potential
blocking operations | sections follow a stack discipline within each thread (the "begin" and "end" macros enforce this since they must be paired and within the same scope)
* Critical sections automatically release and reacquire locks around potential
blocking operations | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c43d6d7-4689-4fd9-9dfc-15851c53a92a | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,717 | supabase-export-v2 | 34dd0293eb2c876f | Module Initialization =====================
Extension modules need to explicitly indicate that they support running with
the GIL disabled; otherwise importing the extension will raise a warning and
enable the GIL at runtime. | trusted_official_docs | CPython Docs | Module Initialization =====================
Extension modules need to explicitly indicate that they support running with
the GIL disabled; otherwise importing the extension will raise a warning and
enable the GIL at runtime. | Module Initialization =====================
Extension modules need to explicitly indicate that they support running with
the GIL disabled; otherwise importing the extension will raise a warning and
enable the GIL at runtime. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
25fabfd9-a240-48a5-9671-9de5b6078908 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,787 | supabase-export-v2 | 7c5e3f39b1897f3e | sections will not deadlock if you attempt to lock the same object twice, they are less efficient than purpose-built reentrant locks for this use case.
* When using :c:macro:`Py_BEGIN_CRITICAL_SECTION2`, the order of the objects
doesn't affect correctness (the implementation handles deadlock avoidance),
but it's good ... | trusted_official_docs | CPython Docs | sections will not deadlock if you attempt to lock the same object twice, they are less efficient than purpose-built reentrant locks for this use case.
* When using :c:macro:`Py_BEGIN_CRITICAL_SECTION2`, the order of the objects
doesn't affect correctness (the implementation handles deadlock avoidance),
but it's good ... | sections will not deadlock if you attempt to lock the same object twice, they are less efficient than purpose-built reentrant locks for this use case.
* When using :c:macro:`Py_BEGIN_CRITICAL_SECTION2`, the order of the objects
doesn't affect correctness (the implementation handles deadlock avoidance),
but it's good ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2cc3b1a6-2d7a-4e2e-bb31-0f239ad19bf1 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,748 | supabase-export-v2 | df41520c55e9afd5 | uses of :c:func:`PyObject_Malloc` in your extension and check that the allocated memory is used for Python objects. Use :c:func:`PyMem_Malloc` to allocate buffers instead of :c:func:`PyObject_Malloc`.
Thread State and GIL APIs
========================= | trusted_official_docs | CPython Docs | uses of :c:func:`PyObject_Malloc` in your extension and check that the allocated memory is used for Python objects. Use :c:func:`PyMem_Malloc` to allocate buffers instead of :c:func:`PyObject_Malloc`.
Thread State and GIL APIs
========================= | uses of :c:func:`PyObject_Malloc` in your extension and check that the allocated memory is used for Python objects. Use :c:func:`PyMem_Malloc` to allocate buffers instead of :c:func:`PyObject_Malloc`.
Thread State and GIL APIs
========================= | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2d64d308-2c96-40e3-b21a-7c78977672d7 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,730 | supabase-export-v2 | 3f71b12f4ff6cabe | Most of the C API is thread-safe, but there are some exceptions.
* **Struct Fields**: Accessing fields in Python C API objects or structs
directly is not thread-safe if the field may be concurrently modified. * **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM`,
:c:macro:`PyList_SET_ITEM`, and macros like
:... | trusted_official_docs | CPython Docs | Most of the C API is thread-safe, but there are some exceptions.
* **Struct Fields**: Accessing fields in Python C API objects or structs
directly is not thread-safe if the field may be concurrently modified. * **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM`,
:c:macro:`PyList_SET_ITEM`, and macros like
:... | Most of the C API is thread-safe, but there are some exceptions.
* **Struct Fields**: Accessing fields in Python C API objects or structs
directly is not thread-safe if the field may be concurrently modified. * **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM`,
:c:macro:`PyList_SET_ITEM`, and macros like
:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2f38fde6-39ce-4637-a49e-582d1beef66a | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,760 | supabase-export-v2 | 9352be1f46e63c8f | What Are Critical Sections? ...........................
Conceptually, critical sections act as a deadlock avoidance layer built on
top of simple mutexes. Each thread maintains a stack of active critical
sections. When a thread needs to acquire a lock associated with a critical
section (e.g., implicitly when calling a t... | trusted_official_docs | CPython Docs | What Are Critical Sections? ...........................
Conceptually, critical sections act as a deadlock avoidance layer built on
top of simple mutexes. Each thread maintains a stack of active critical
sections. When a thread needs to acquire a lock associated with a critical
section (e.g., implicitly when calling a t... | What Are Critical Sections? ...........................
Conceptually, critical sections act as a deadlock avoidance layer built on
top of simple mutexes. Each thread maintains a stack of active critical
sections. When a thread needs to acquire a lock associated with a critical
section (e.g., implicitly when calling a t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2fda72b3-828b-465c-84db-153fb54316b9 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,713 | supabase-export-v2 | 29e30c674914a28c | defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build::
#ifdef Py_GIL_DISABLED
/* code that only runs in the free-threaded build */
#endif | trusted_official_docs | CPython Docs | defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build::
#ifdef Py_GIL_DISABLED
/* code that only runs in the free-threaded build */
#endif | defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build::
#ifdef Py_GIL_DISABLED
/* code that only runs in the free-threaded build */
#endif | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
30be6a13-8fc7-4956-a42f-60b56b795501 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,780 | supabase-export-v2 | 9d2d50056b437657 | sections to lock multiple objects at once, as the inner critical section may suspend the outer ones. Instead, use :c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simultaneously.
Note that the locks described above are only :c:type:`PyMutex` based locks. The critical section implementation does not know about ... | trusted_official_docs | CPython Docs | sections to lock multiple objects at once, as the inner critical section may suspend the outer ones. Instead, use :c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simultaneously.
Note that the locks described above are only :c:type:`PyMutex` based locks. The critical section implementation does not know about ... | sections to lock multiple objects at once, as the inner critical section may suspend the outer ones. Instead, use :c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simultaneously.
Note that the locks described above are only :c:type:`PyMutex` based locks. The critical section implementation does not know about ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
357582f3-32bd-4ed2-a4a7-f97c39ce3ea9 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,759 | supabase-export-v2 | 43837031e177198e | the internal critical section implementation directly, understanding their behavior is crucial when using certain C API functions or managing shared state in the free-threaded build.
What Are Critical Sections? ........................... | trusted_official_docs | CPython Docs | the internal critical section implementation directly, understanding their behavior is crucial when using certain C API functions or managing shared state in the free-threaded build.
What Are Critical Sections? ........................... | the internal critical section implementation directly, understanding their behavior is crucial when using certain C API functions or managing shared state in the free-threaded build.
What Are Critical Sections? ........................... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3bc4b511-b683-41b9-8be8-3378fbc52735 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,751 | supabase-export-v2 | 42b33a6a39433c71 | * :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` * :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread` * :c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS`
These functions should still be used in the free-threaded build to manage
thread state even when the :term:`GIL` is disa... | trusted_official_docs | CPython Docs | * :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` * :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread` * :c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS`
These functions should still be used in the free-threaded build to manage
thread state even when the :term:`GIL` is disa... | * :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release` * :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread` * :c:macro:`Py_BEGIN_ALLOW_THREADS` and :c:macro:`Py_END_ALLOW_THREADS`
These functions should still be used in the free-threaded build to manage
thread state even when the :term:`GIL` is disa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4551edfd-ad47-4765-baa4-56977729d260 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,755 | supabase-export-v2 | 34bb0039de421b2a | by the GIL. You may need to add locking to protect this state. The approach will depend on your extension, but some common patterns include:
* **Caches**: global caches are a common source of shared state. Consider
using a lock to protect the cache or disabling it in the free-threaded build
if the cache is not critic... | trusted_official_docs | CPython Docs | by the GIL. You may need to add locking to protect this state. The approach will depend on your extension, but some common patterns include:
* **Caches**: global caches are a common source of shared state. Consider
using a lock to protect the cache or disabling it in the free-threaded build
if the cache is not critic... | by the GIL. You may need to add locking to protect this state. The approach will depend on your extension, but some common patterns include:
* **Caches**: global caches are a common source of shared state. Consider
using a lock to protect the cache or disabling it in the free-threaded build
if the cache is not critic... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5770e7c1-c853-4392-883a-937d9a54e08d | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,741 | supabase-export-v2 | f6c1ce8ce6d3c6a4 | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GetObject` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GET_OBJECT` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+------... | trusted_official_docs | CPython Docs | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GetObject` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GET_OBJECT` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+------... | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GetObject` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+-----------------------------------+ | :c:func:`!PyWeakref_GET_OBJECT` | :c:func:`PyWeakref_GetRef` | +-----------------------------------+------... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5839f9f9-de1b-4d52-8b03-58941a719ed9 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,794 | supabase-export-v2 | fe754846b19fceef | Do **not** lock ``ob_mutex`` directly with ``PyMutex_Lock(&obj->ob_mutex)``. Mixing direct ``PyMutex_Lock`` calls with the critical section API on the same mutex can cause deadlocks.
Even if your own code never uses critical sections on a particular object type,
**CPython internals may use the critical section API on a... | trusted_official_docs | CPython Docs | Do **not** lock ``ob_mutex`` directly with ``PyMutex_Lock(&obj->ob_mutex)``. Mixing direct ``PyMutex_Lock`` calls with the critical section API on the same mutex can cause deadlocks.
Even if your own code never uses critical sections on a particular object type,
**CPython internals may use the critical section API on a... | Do **not** lock ``ob_mutex`` directly with ``PyMutex_Lock(&obj->ob_mutex)``. Mixing direct ``PyMutex_Lock`` calls with the critical section API on the same mutex can cause deadlocks.
Even if your own code never uses critical sections on a particular object type,
**CPython internals may use the critical section API on a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
59bcf118-2d2d-477e-b470-f9403b5387c8 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,782 | supabase-export-v2 | c5c305bbdf1356b1 | Important Considerations ........................
* Critical sections may temporarily release their locks, allowing other threads
to modify the protected data. Be careful about making assumptions about the
state of the data after operations that might block. | trusted_official_docs | CPython Docs | Important Considerations ........................
* Critical sections may temporarily release their locks, allowing other threads
to modify the protected data. Be careful about making assumptions about the
state of the data after operations that might block. | Important Considerations ........................
* Critical sections may temporarily release their locks, allowing other threads
to modify the protected data. Be careful about making assumptions about the
state of the data after operations that might block. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bd6d39c-31c3-46ac-a231-57ee774f49c6 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,796 | supabase-export-v2 | fd998e789b40ccea | separate :c:type:`PyMutex` field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is very lightweight, so there is negligible cost to having an additional one.
Building Extensions for the Free-Threaded Build
=============================================== | trusted_official_docs | CPython Docs | separate :c:type:`PyMutex` field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is very lightweight, so there is negligible cost to having an additional one.
Building Extensions for the Free-Threaded Build
=============================================== | separate :c:type:`PyMutex` field (or another synchronization primitive) to your object struct. :c:type:`PyMutex` is very lightweight, so there is negligible cost to having an additional one.
Building Extensions for the Free-Threaded Build
=============================================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64f9a038-7fb7-45db-92f7-f9ecb6c29d44 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,797 | supabase-export-v2 | fba93d92bcc3eaf5 | Building Extensions for the Free-Threaded Build ===============================================
C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix. | trusted_official_docs | CPython Docs | Building Extensions for the Free-Threaded Build ===============================================
C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix. | Building Extensions for the Free-Threaded Build ===============================================
C API extensions need to be built specifically for the free-threaded build. The wheels, shared libraries, and binaries are indicated by a ``t`` suffix. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67cebf08-27b9-478a-bca1-6a9bf5d8d480 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,779 | supabase-export-v2 | 3553f7f51e4a694a | 2. When the blocking operation completes, only the top-most critical section is reacquired first
This means you cannot rely on nested critical sections to lock multiple objects
at once, as the inner critical section may suspend the outer ones. Instead, use
:c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simul... | trusted_official_docs | CPython Docs | 2. When the blocking operation completes, only the top-most critical section is reacquired first
This means you cannot rely on nested critical sections to lock multiple objects
at once, as the inner critical section may suspend the outer ones. Instead, use
:c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simul... | 2. When the blocking operation completes, only the top-most critical section is reacquired first
This means you cannot rely on nested critical sections to lock multiple objects
at once, as the inner critical section may suspend the outer ones. Instead, use
:c:macro:`Py_BEGIN_CRITICAL_SECTION2` to lock two objects simul... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
69117a90-2a81-463b-bf9e-723675696769 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,752 | supabase-export-v2 | 0983e6490e32a086 | thread outside of Python, you must call :c:func:`PyGILState_Ensure` before calling into the Python API to ensure that the thread has a valid Python thread state.
You should continue to call :c:func:`PyEval_SaveThread` or
:c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or
lock acquisitions, to ... | trusted_official_docs | CPython Docs | thread outside of Python, you must call :c:func:`PyGILState_Ensure` before calling into the Python API to ensure that the thread has a valid Python thread state.
You should continue to call :c:func:`PyEval_SaveThread` or
:c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or
lock acquisitions, to ... | thread outside of Python, you must call :c:func:`PyGILState_Ensure` before calling into the Python API to ensure that the thread has a valid Python thread state.
You should continue to call :c:func:`PyEval_SaveThread` or
:c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or
lock acquisitions, to ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6cf0c9ec-f4e9-40ca-9c35-a1f2e77915fb | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,800 | supabase-export-v2 | e451d7c39ace1896 | Limited C API and Stable ABI ............................
The free-threaded build does not currently support the
:ref:`Limited C API <limited-c-api>` or the stable ABI. If you use
`setuptools <https://setuptools.pypa.io/en/latest/setuptools.html>`_ to build
your extension and currently set ``py_limited_api=True`` you c... | trusted_official_docs | CPython Docs | Limited C API and Stable ABI ............................
The free-threaded build does not currently support the
:ref:`Limited C API <limited-c-api>` or the stable ABI. If you use
`setuptools <https://setuptools.pypa.io/en/latest/setuptools.html>`_ to build
your extension and currently set ``py_limited_api=True`` you c... | Limited C API and Stable ABI ............................
The free-threaded build does not currently support the
:ref:`Limited C API <limited-c-api>` or the stable ABI. If you use
`setuptools <https://setuptools.pypa.io/en/latest/setuptools.html>`_ to build
your extension and currently set ``py_limited_api=True`` you c... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6d806eef-792f-4c46-87d9-166e0f4e8f52 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,768 | supabase-export-v2 | d79b03aaaa852c53 | // read the count, returns new reference to internal count value PyObject *result; Py_BEGIN_CRITICAL_SECTION(obj); result = Py_NewRef(obj->count); Py_END_CRITICAL_SECTION(); return result;
// write the count, consumes reference from new_count
Py_BEGIN_CRITICAL_SECTION(obj);
obj->count = new_count;
Py_END_CRITICAL_SE... | trusted_official_docs | CPython Docs | // read the count, returns new reference to internal count value PyObject *result; Py_BEGIN_CRITICAL_SECTION(obj); result = Py_NewRef(obj->count); Py_END_CRITICAL_SECTION(); return result;
// write the count, consumes reference from new_count
Py_BEGIN_CRITICAL_SECTION(obj);
obj->count = new_count;
Py_END_CRITICAL_SE... | // read the count, returns new reference to internal count value PyObject *result; Py_BEGIN_CRITICAL_SECTION(obj); result = Py_NewRef(obj->count); Py_END_CRITICAL_SECTION(); return result;
// write the count, consumes reference from new_count
Py_BEGIN_CRITICAL_SECTION(obj);
obj->count = new_count;
Py_END_CRITICAL_SE... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7fd6a3c2-2cd2-4228-9137-605d4a6608f2 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,742 | supabase-export-v2 | 76d6d2e1ec6fc7c4 | dictionaries in function calls; those keyword argument dictionaries are effectively private (not accessible by other threads), so using borrowed references in that context is safe.
Some of these functions were added in Python 3.13. You can use the
`pythoncapi-compat <https://github.com/python/pythoncapi-compat>`_ packa... | trusted_official_docs | CPython Docs | dictionaries in function calls; those keyword argument dictionaries are effectively private (not accessible by other threads), so using borrowed references in that context is safe.
Some of these functions were added in Python 3.13. You can use the
`pythoncapi-compat <https://github.com/python/pythoncapi-compat>`_ packa... | dictionaries in function calls; those keyword argument dictionaries are effectively private (not accessible by other threads), so using borrowed references in that context is safe.
Some of these functions were added in Python 3.13. You can use the
`pythoncapi-compat <https://github.com/python/pythoncapi-compat>`_ packa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84a561bb-f6ff-471e-8160-e9b981aadd6a | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,738 | supabase-export-v2 | 8a54b5fb2259d957 | .. _borrowed-references:
Some C API functions return :term:`borrowed references <borrowed reference>`. These APIs are not thread-safe if the containing object is modified
concurrently. For example, it's not safe to use :c:func:`PyList_GetItem`
if the list may be modified concurrently. | trusted_official_docs | CPython Docs | .. _borrowed-references:
Some C API functions return :term:`borrowed references <borrowed reference>`. These APIs are not thread-safe if the containing object is modified
concurrently. For example, it's not safe to use :c:func:`PyList_GetItem`
if the list may be modified concurrently. | .. _borrowed-references:
Some C API functions return :term:`borrowed references <borrowed reference>`. These APIs are not thread-safe if the containing object is modified
concurrently. For example, it's not safe to use :c:func:`PyList_GetItem`
if the list may be modified concurrently. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8cd4b420-cf7b-47f8-b095-860b4fc04f98 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,770 | supabase-export-v2 | 491d25f73964ed3f | How Critical Sections Work ..........................
Unlike traditional locks, critical sections do not guarantee exclusive access
throughout their entire duration. If a thread would block while holding a
critical section (e.g., by acquiring another lock or performing I/O), the
critical section is temporarily suspende... | trusted_official_docs | CPython Docs | How Critical Sections Work ..........................
Unlike traditional locks, critical sections do not guarantee exclusive access
throughout their entire duration. If a thread would block while holding a
critical section (e.g., by acquiring another lock or performing I/O), the
critical section is temporarily suspende... | How Critical Sections Work ..........................
Unlike traditional locks, critical sections do not guarantee exclusive access
throughout their entire duration. If a thread would block while holding a
critical section (e.g., by acquiring another lock or performing I/O), the
critical section is temporarily suspende... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93005445-a259-455f-91a1-3624e514c17e | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,735 | supabase-export-v2 | 5ada9b717b650875 | which does not lock the dictionary. You should use :c:macro:`Py_BEGIN_CRITICAL_SECTION` to protect the dictionary while iterating over it if the dictionary may be concurrently modified::
Py_BEGIN_CRITICAL_SECTION(dict);
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &key, &value)) {
... }... | trusted_official_docs | CPython Docs | which does not lock the dictionary. You should use :c:macro:`Py_BEGIN_CRITICAL_SECTION` to protect the dictionary while iterating over it if the dictionary may be concurrently modified::
Py_BEGIN_CRITICAL_SECTION(dict);
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &key, &value)) {
... }... | which does not lock the dictionary. You should use :c:macro:`Py_BEGIN_CRITICAL_SECTION` to protect the dictionary while iterating over it if the dictionary may be concurrently modified::
Py_BEGIN_CRITICAL_SECTION(dict);
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &key, &value)) {
... }... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ab44b6f-6dd4-47a6-8feb-404a6ec84d44 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,739 | supabase-export-v2 | 564c30f8286b774b | are not thread-safe if the containing object is modified concurrently. For example, it's not safe to use :c:func:`PyList_GetItem` if the list may be modified concurrently.
The following table lists some borrowed reference APIs and their replacements
that return :term:`strong references <strong reference>`. | trusted_official_docs | CPython Docs | are not thread-safe if the containing object is modified concurrently. For example, it's not safe to use :c:func:`PyList_GetItem` if the list may be modified concurrently.
The following table lists some borrowed reference APIs and their replacements
that return :term:`strong references <strong reference>`. | are not thread-safe if the containing object is modified concurrently. For example, it's not safe to use :c:func:`PyList_GetItem` if the list may be modified concurrently.
The following table lists some borrowed reference APIs and their replacements
that return :term:`strong references <strong reference>`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9adf1358-795e-4dcd-8d4b-a75e38b00a4c | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,753 | supabase-export-v2 | 7922545d7648644f | call :c:func:`PyEval_SaveThread` or :c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or lock acquisitions, to allow other threads to run the :term:`cyclic garbage collector <garbage collection>`.
Protecting Internal Extension State
=================================== | trusted_official_docs | CPython Docs | call :c:func:`PyEval_SaveThread` or :c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or lock acquisitions, to allow other threads to run the :term:`cyclic garbage collector <garbage collection>`.
Protecting Internal Extension State
=================================== | call :c:func:`PyEval_SaveThread` or :c:macro:`Py_BEGIN_ALLOW_THREADS` around blocking operations, such as I/O or lock acquisitions, to allow other threads to run the :term:`cyclic garbage collector <garbage collection>`.
Protecting Internal Extension State
=================================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ca49cd0-321d-4f4f-a5c2-4998f86c5289 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,711 | supabase-export-v2 | 252bc36455f752ba | the :term:`global interpreter lock` (GIL) disabled in a configuration called :term:`free threading`. This document describes how to adapt C API extensions to support free threading.
Identifying the Free-Threaded Build in C
======================================== | trusted_official_docs | CPython Docs | the :term:`global interpreter lock` (GIL) disabled in a configuration called :term:`free threading`. This document describes how to adapt C API extensions to support free threading.
Identifying the Free-Threaded Build in C
======================================== | the :term:`global interpreter lock` (GIL) disabled in a configuration called :term:`free threading`. This document describes how to adapt C API extensions to support free threading.
Identifying the Free-Threaded Build in C
======================================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e550eb2-0f37-470a-b5f6-3c2df1585262 | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,791 | supabase-export-v2 | c705f46ec2749a03 | Per-Object Locks (``ob_mutex``) ...............................
In the free-threaded build, each Python object contains a :c:member:`~PyObject.ob_mutex`
field of type :c:type:`PyMutex`. This mutex is **reserved for use by the
critical section API** (:c:macro:`Py_BEGIN_CRITICAL_SECTION` /
:c:macro:`Py_END_CRITICAL_SECTI... | trusted_official_docs | CPython Docs | Per-Object Locks (``ob_mutex``) ...............................
In the free-threaded build, each Python object contains a :c:member:`~PyObject.ob_mutex`
field of type :c:type:`PyMutex`. This mutex is **reserved for use by the
critical section API** (:c:macro:`Py_BEGIN_CRITICAL_SECTION` /
:c:macro:`Py_END_CRITICAL_SECTI... | Per-Object Locks (``ob_mutex``) ...............................
In the free-threaded build, each Python object contains a :c:member:`~PyObject.ob_mutex`
field of type :c:type:`PyMutex`. This mutex is **reserved for use by the
critical section API** (:c:macro:`Py_BEGIN_CRITICAL_SECTION` /
:c:macro:`Py_END_CRITICAL_SECTI... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a14d147e-07d3-4ec5-af7c-9f1f5e303afc | CPython Docs | file://datasets/cpython/Doc/howto/free-threading-extensions.rst | unknown | 3895b142-ba85-4923-b7b4-60bdc2b959f5 | 58,712 | supabase-export-v2 | 7586845cbd3910eb | Identifying the Free-Threaded Build in C ========================================
The CPython C API exposes the ``Py_GIL_DISABLED`` macro: in the free-threaded
build it's defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build:: | trusted_official_docs | CPython Docs | Identifying the Free-Threaded Build in C ========================================
The CPython C API exposes the ``Py_GIL_DISABLED`` macro: in the free-threaded
build it's defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build:: | Identifying the Free-Threaded Build in C ========================================
The CPython C API exposes the ``Py_GIL_DISABLED`` macro: in the free-threaded
build it's defined to ``1``, and in the regular build it's not defined. You can use it to enable code that only runs under the free-threaded build:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.