This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyFunction_GetAnnotations returning Tuple vs Dict
Type: Stage: resolved
Components: C API Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, cpu, methane, miss-islington, pablogsal, serhiy.storchaka
Priority: Keywords: patch

Created on 2022-01-03 03:16 by cpu, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30409 merged methane, 2022-01-05 01:17
PR 30420 merged miss-islington, 2022-01-05 12:26
Messages (6)
msg409555 - (view) Author: Daniel McCarney (cpu) Date: 2022-01-03 03:16
Hi there,

This is my first Python bug, hope I haven't missed anything important.

I noticed that the PyFunction_GetAnnotations function from the C API is returning a PyTuple when I link Python 3.10 where historically it returned a PyDict.

The documentation for PyFunction_GetAnnotations for 3.10 (here[0]) says its return can be:
> a mutable dictionary or NULL

I'm not sure if:
* This is user error and I should adapt to this case in my dependent code when using Python 3.10+.
* This is a documentation error, and it should say "a mutable dictionary, set, or NULL"
* This is a regression in the C API that should be fixed.

I've made a small reproduction program (here[1]) that can be used to quickly demonstrate the difference in return type between the two Python versions for the same C program and .py inputs.

I also noticed that issue42202 (here[2]) landed an optimization in 3.10.x that changed the internal representation of annotations to a set - could that possibly be related? I'm not 100% sure!

Thanks!

[0]: https://docs.python.org/3/c-api/function.html#c.PyFunction_GetAnnotations
[1]: https://github.com/cpu/pyfunction_getannotations_test
[2]: https://bugs.python.org/issue42202
msg409726 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-01-04 23:45
Pablo, should this be a release blocker?
msg409729 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-05 00:36
Yeah, the docs mention explicitly that is a dictionary or NULL.
msg409730 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-05 00:38
I am quite sure this is due to PR 23316
msg409759 - (view) Author: miss-islington (miss-islington) Date: 2022-01-05 12:25
New changeset 46e4c257e7c26c813620232135781e6c53fe8d4d by Inada Naoki in branch 'main':
bpo-46236: Fix PyFunction_GetAnnotations() returned tuple. (GH-30409)
https://github.com/python/cpython/commit/46e4c257e7c26c813620232135781e6c53fe8d4d
msg409763 - (view) Author: miss-islington (miss-islington) Date: 2022-01-05 13:12
New changeset da8be157f4e275c4c32b9199f1466ed7e52f62cf by Miss Islington (bot) in branch '3.10':
bpo-46236: Fix PyFunction_GetAnnotations() returned tuple. (GH-30409)
https://github.com/python/cpython/commit/da8be157f4e275c4c32b9199f1466ed7e52f62cf
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90394
2022-01-05 13:12:40pablogsalsetpriority: release blocker ->
status: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.11
2022-01-05 13:12:26miss-islingtonsetmessages: + msg409763
2022-01-05 12:26:06miss-islingtonsetpull_requests: + pull_request28624
2022-01-05 12:25:58miss-islingtonsetnosy: + miss-islington
messages: + msg409759
2022-01-05 01:17:42methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request28615
2022-01-05 00:38:08pablogsalsetmessages: + msg409730
2022-01-05 00:37:03pablogsalsetnosy: + serhiy.storchaka
2022-01-05 00:36:28pablogsalsetpriority: normal -> release blocker

messages: + msg409729
2022-01-04 23:45:25Dennis Sweeneysetnosy: + Dennis Sweeney, pablogsal
messages: + msg409726
2022-01-03 04:30:36Dennis Sweeneysetnosy: + methane
2022-01-03 03:16:05cpucreate