<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/cpython-git.git/Objects/funcobject.c, branch enum-lost-fixes</title>
<subtitle>github.com: python/cpython.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/'/>
<entry>
<title>bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) (GH-27162)</title>
<updated>2021-07-15T13:42:11+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-07-15T13:42:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=2ce8af3cbcb368a35a05a5a9f97a09405124f239'/>
<id>2ce8af3cbcb368a35a05a5a9f97a09405124f239</id>
<content type='text'>
Patch by Erik Welch.

bpo-19072 (GH-8405) allows `classmethod` to wrap other descriptors, but this does
not work when the wrapped descriptor mimics classmethod.  The current PR fixes
this.

In Python 3.8 and before, one could create a callable descriptor such that this
works as expected (see Lib/test/test_decorators.py for examples):
```python
class A:
    @myclassmethod
    def f1(cls):
        return cls

    @classmethod
    @myclassmethod
    def f2(cls):
        return cls
```
In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, it
returns `type(A)`.  This PR make `A.f2()` return `A` again.

As of GH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.
This allows one to chain `@classmethod` and `@property` together.  When
using classmethod-like descriptors, it's the second argument to `__get__`--the
owner or the type--that is important, but this argument is currently missing.
Since it is None, the "owner" argument is assumed to be the type of the first
argument, which, in this case, is wrong (we want `A`, not `type(A)`).

This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has
`__get__`.

Co-authored-by: Erik Welch &lt;erik.n.welch@gmail.com&gt;
(cherry picked from commit b83861f0265e07207a6ae2c49c40fa8f447893f2)</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Patch by Erik Welch.

bpo-19072 (GH-8405) allows `classmethod` to wrap other descriptors, but this does
not work when the wrapped descriptor mimics classmethod.  The current PR fixes
this.

In Python 3.8 and before, one could create a callable descriptor such that this
works as expected (see Lib/test/test_decorators.py for examples):
```python
class A:
    @myclassmethod
    def f1(cls):
        return cls

    @classmethod
    @myclassmethod
    def f2(cls):
        return cls
```
In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, it
returns `type(A)`.  This PR make `A.f2()` return `A` again.

As of GH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.
This allows one to chain `@classmethod` and `@property` together.  When
using classmethod-like descriptors, it's the second argument to `__get__`--the
owner or the type--that is important, but this argument is currently missing.
Since it is None, the "owner" argument is assumed to be the type of the first
argument, which, in this case, is wrong (we want `A`, not `type(A)`).

This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has
`__get__`.

Co-authored-by: Erik Welch &lt;erik.n.welch@gmail.com&gt;
(cherry picked from commit b83861f0265e07207a6ae2c49c40fa8f447893f2)</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-43682: Make staticmethod objects callable (GH-25117)</title>
<updated>2021-04-11T22:21:22+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-04-11T22:21:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=553ee2781a37ac9d2068da3e1325a780ca79e21e'/>
<id>553ee2781a37ac9d2068da3e1325a780ca79e21e</id>
<content type='text'>
Static methods (@staticmethod) are now callable as regular functions.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Static methods (@staticmethod) are now callable as regular functions.</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-43682: @staticmethod inherits attributes (GH-25268)</title>
<updated>2021-04-09T15:51:22+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-04-09T15:51:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=507a574de31a1bd7fed8ba4f04afa285d985109b'/>
<id>507a574de31a1bd7fed8ba4f04afa285d985109b</id>
<content type='text'>
Static methods (@staticmethod) and class methods (@classmethod) now
inherit the method attributes (__module__, __name__, __qualname__,
__doc__, __annotations__) and have a new __wrapped__ attribute.

Changes:

* Add a repr() method to staticmethod and classmethod types.
* Add tests on the @classmethod decorator.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Static methods (@staticmethod) and class methods (@classmethod) now
inherit the method attributes (__module__, __name__, __qualname__,
__doc__, __annotations__) and have a new __wrapped__ attribute.

Changes:

* Add a repr() method to staticmethod and classmethod types.
* Add tests on the @classmethod decorator.</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-43541: Fix PyEval_EvalCodeEx() regression (GH-24918)</title>
<updated>2021-03-18T13:51:24+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-03-18T13:51:24+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=fc980e0be19776ee05dfc5380eb5d6a8092935cb'/>
<id>fc980e0be19776ee05dfc5380eb5d6a8092935cb</id>
<content type='text'>
* Remove an assertion which required CO_NEWLOCALS and CO_OPTIMIZED
  code flags. It is ok to call this function on a code with these
  flags set.
* Fix reference counting on builtins: remove Py_DECREF().
  Fix regression introduced in the
  commit 46496f9d12582bf11f4911ad0f23315d6f277907.

Add also a comment to document that _PyEval_BuiltinsFromGlobals()
returns a borrowed reference.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Remove an assertion which required CO_NEWLOCALS and CO_OPTIMIZED
  code flags. It is ok to call this function on a code with these
  flags set.
* Fix reference counting on builtins: remove Py_DECREF().
  Fix regression introduced in the
  commit 46496f9d12582bf11f4911ad0f23315d6f277907.

Add also a comment to document that _PyEval_BuiltinsFromGlobals()
returns a borrowed reference.</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42990: Functions inherit current builtins (GH-24564)</title>
<updated>2021-02-20T14:17:18+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-02-20T14:17:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=46496f9d12582bf11f4911ad0f23315d6f277907'/>
<id>46496f9d12582bf11f4911ad0f23315d6f277907</id>
<content type='text'>
The types.FunctionType constructor now inherits the current builtins
if the globals dictionary has no "__builtins__" key, rather than
using {"None": None} as builtins: same behavior as eval() and exec()
functions.

Defining a function with "def function(...): ..." in Python is not
affected, globals cannot be overriden with this syntax: it also
inherits the current builtins.

PyFrame_New(), PyEval_EvalCode(), PyEval_EvalCodeEx(),
PyFunction_New() and PyFunction_NewWithQualName() now inherits the
current builtins namespace if the globals dictionary has no
"__builtins__" key.

* Add _PyEval_GetBuiltins() function.
* _PyEval_BuiltinsFromGlobals() now uses _PyEval_GetBuiltins() if
  builtins cannot be found in globals.
* Add tstate parameter to _PyEval_BuiltinsFromGlobals().</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The types.FunctionType constructor now inherits the current builtins
if the globals dictionary has no "__builtins__" key, rather than
using {"None": None} as builtins: same behavior as eval() and exec()
functions.

Defining a function with "def function(...): ..." in Python is not
affected, globals cannot be overriden with this syntax: it also
inherits the current builtins.

PyFrame_New(), PyEval_EvalCode(), PyEval_EvalCodeEx(),
PyFunction_New() and PyFunction_NewWithQualName() now inherits the
current builtins namespace if the globals dictionary has no
"__builtins__" key.

* Add _PyEval_GetBuiltins() function.
* _PyEval_BuiltinsFromGlobals() now uses _PyEval_GetBuiltins() if
  builtins cannot be found in globals.
* Add tstate parameter to _PyEval_BuiltinsFromGlobals().</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42990: Refactor _PyFrame_New_NoTrack() (GH-24566)</title>
<updated>2021-02-18T18:20:16+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-02-18T18:20:16+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=44085a3fc9a150478aec1872dd1079c60dcc42f6'/>
<id>44085a3fc9a150478aec1872dd1079c60dcc42f6</id>
<content type='text'>
* Refactor _PyFrame_New_NoTrack() and PyFunction_NewWithQualName()
  code.
* PyFrame_New() checks for _PyEval_BuiltinsFromGlobals() failure.
* Fix a ref leak in _PyEval_BuiltinsFromGlobals() error path.
* Complete PyFunction_GetModule() documentation: it returns a
  borrowed reference and it can return NULL.
* Move _PyEval_BuiltinsFromGlobals() definition to the internal C
  API.
* PyFunction_NewWithQualName() uses _Py_IDENTIFIER() API for the
  "__name__" string to make it compatible with subinterpreters.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Refactor _PyFrame_New_NoTrack() and PyFunction_NewWithQualName()
  code.
* PyFrame_New() checks for _PyEval_BuiltinsFromGlobals() failure.
* Fix a ref leak in _PyEval_BuiltinsFromGlobals() error path.
* Complete PyFunction_GetModule() documentation: it returns a
  borrowed reference and it can return NULL.
* Move _PyEval_BuiltinsFromGlobals() definition to the internal C
  API.
* PyFunction_NewWithQualName() uses _Py_IDENTIFIER() API for the
  "__name__" string to make it compatible with subinterpreters.</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42990: Add __builtins__ attribute to functions (GH-24559)</title>
<updated>2021-02-18T11:35:37+00:00</updated>
<author>
<name>Victor Stinner</name>
<email>vstinner@python.org</email>
</author>
<published>2021-02-18T11:35:37+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=a3c3ffa68e6fc4524b1149a6a14d56c3a2e9b612'/>
<id>a3c3ffa68e6fc4524b1149a6a14d56c3a2e9b612</id>
<content type='text'>
Expose the new PyFunctionObject.func_builtins member in Python as a
new __builtins__ attribute on functions.

Document also the behavior change in What's New in Python 3.10.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Expose the new PyFunctionObject.func_builtins member in Python as a
new __builtins__ attribute on functions.

Document also the behavior change in What's New in Python 3.10.</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42990: Further refactoring of PyEval_ functions. (GH-24368)</title>
<updated>2021-02-01T10:42:03+00:00</updated>
<author>
<name>Mark Shannon</name>
<email>mark@hotpy.org</email>
</author>
<published>2021-02-01T10:42:03+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=0332e569c12d3dc97171546c6dc10e42c27de34b'/>
<id>0332e569c12d3dc97171546c6dc10e42c27de34b</id>
<content type='text'>
* Further refactoring of PyEval_EvalCode and friends. Break into make-frame, and eval-frame parts.

* Simplify function vector call using new _PyEval_Vector.

* Remove unused internal functions: _PyEval_EvalCodeWithName and _PyEval_EvalCode.

* Don't use legacy function PyEval_EvalCodeEx.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Further refactoring of PyEval_EvalCode and friends. Break into make-frame, and eval-frame parts.

* Simplify function vector call using new _PyEval_Vector.

* Remove unused internal functions: _PyEval_EvalCodeWithName and _PyEval_EvalCode.

* Don't use legacy function PyEval_EvalCodeEx.
</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42990: Introduce 'frame constructor' struct to simplify API for PyEval_CodeEval and friends (GH-24298)</title>
<updated>2021-01-29T13:24:55+00:00</updated>
<author>
<name>Mark Shannon</name>
<email>mark@hotpy.org</email>
</author>
<published>2021-01-29T13:24:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=d6c33fbd346765c6a8654dccacb2338006bf2b47'/>
<id>d6c33fbd346765c6a8654dccacb2338006bf2b47</id>
<content type='text'>
* Introduce 'frame constructor' to simplify API for frame creation

* Embed struct using a macro to conform to PEP 7</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Introduce 'frame constructor' to simplify API for frame creation

* Embed struct using a macro to conform to PEP 7</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42202: Store func annotations as a tuple (GH-23316)</title>
<updated>2020-11-25T10:43:18+00:00</updated>
<author>
<name>Yurii Karabas</name>
<email>1998uriyyo@gmail.com</email>
</author>
<published>2020-11-25T10:43:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/cpython-git.git/commit/?id=7301979b23406220510dd2c7934a21b41b647119'/>
<id>7301979b23406220510dd2c7934a21b41b647119</id>
<content type='text'>
Reduce memory footprint and improve performance of loading modules having many func annotations.

  &gt;&gt;&gt; sys.getsizeof({"a":"int","b":"int","return":"int"})
  232
  &gt;&gt;&gt; sys.getsizeof(("a","int","b","int","return","int"))
  88

The tuple is converted into dict on the fly when `func.__annotations__` is accessed first.

Co-authored-by: Serhiy Storchaka &lt;storchaka@gmail.com&gt;
Co-authored-by: Inada Naoki &lt;songofacandy@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Reduce memory footprint and improve performance of loading modules having many func annotations.

  &gt;&gt;&gt; sys.getsizeof({"a":"int","b":"int","return":"int"})
  232
  &gt;&gt;&gt; sys.getsizeof(("a","int","b","int","return","int"))
  88

The tuple is converted into dict on the fly when `func.__annotations__` is accessed first.

Co-authored-by: Serhiy Storchaka &lt;storchaka@gmail.com&gt;
Co-authored-by: Inada Naoki &lt;songofacandy@gmail.com&gt;</pre>
</div>
</content>
</entry>
</feed>
