[New-bugs-announce] [issue46236] PyFunction_GetAnnotations returning Tuple vs Dict
Daniel McCarney
report at bugs.python.org
Sun Jan 2 22:16:05 EST 2022
New submission from Daniel McCarney <daniel at binaryparadox.net>:
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
----------
components: C API
messages: 409555
nosy: cpu
priority: normal
severity: normal
status: open
title: PyFunction_GetAnnotations returning Tuple vs Dict
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46236>
_______________________________________
More information about the New-bugs-announce
mailing list