Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port mypyc to Python 3.11: use Py_SET_SIZE() #11652

Merged
merged 1 commit into from
Dec 3, 2021
Merged

Port mypyc to Python 3.11: use Py_SET_SIZE() #11652

merged 1 commit into from
Dec 3, 2021

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 2, 2021

"Py_TYPE(t) = metaclass;" fails with a compiler error on Python 3.11:

Have you read the Contributing Guidelines?

(Once you have, delete this section. If you leave it in, your PR may be closed without action.)

Description

(Explain how this PR changes mypy.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

"Py_TYPE(t) = metaclass;" fails with a compiler error on Python 3.11:

* https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes
* https://docs.python.org/dev/c-api/structures.html#c.Py_TYPE

* Replace "Py_TYPE(t) = metaclass;" with "Py_SET_TYPE(t, metaclass);"
* Replace "Py_SIZE(self) = newsize;" with "Py_SET_SIZE(self, newsize);"
* Add a copy of pythoncapi_compat.h header to add Py_SET_TYPE() and
  Py_SET_SIZE() functions to Python 3.8 and older:
  https://github.com/pythoncapi/pythoncapi_compat
@vstinner
Copy link
Member Author

vstinner commented Dec 2, 2021

I'm the author of the Py_SIZE() change in Python 3.11 :-) It has been approved by the Steering Council: python/steering-council#79

I'm also working on a PEP which changes other macros and explains the rationale for the Py_SIZE() change, see: https://www.python.org/dev/peps/pep-0674/

Moreover, I'm the author of the pythoncapi_compat project and its pythoncapi_compat.h header file: https://github.com/pythoncapi/pythoncapi_compat I'm trying to propose it as a standard way to support multiple Python versions with a single C code base. The header provides new C API functions on old Python versions.

@vstinner
Copy link
Member Author

vstinner commented Dec 2, 2021

Right now, I cannot run runtests.py with Python 3.11 because python3 -m pip install -r test-requirements.txt fails on installing typed-ast:

    gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -O0 -fPIC -Iast27/Include -I/home/vstinner/dev/mypy/env/include -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c ast27/Python/mystrtoul.c -o build/temp.linux-x86_64-3.11-pydebug/ast27/Python/mystrtoul.o
    ast27/Python/mystrtoul.c: In function ‘Ta27OS_strtoul’:
    ast27/Python/mystrtoul.c:112:21: error: ‘_PyLong_DigitValue’ undeclared (first use in this function)
      112 |                 if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
          |                     ^~~~~~~~~~~~~~~~~~

@vstinner
Copy link
Member Author

vstinner commented Dec 2, 2021

Right now, I cannot run runtests.py with Python 3.11 because python3 -m pip install -r test-requirements.txt fails on installing typed-ast:

Issue already reported upstream: python/typed_ast#167

@vstinner
Copy link
Member Author

vstinner commented Dec 2, 2021

I also got build issues when trying to install the lxml dependency. Cython 0.29.24 is not compatible with Python 3.11 yet: the cython/cython@e138a84 change (part of the 0.29.x branch) is needed, but there is no Cython 0.29.x release including this change yet. I asked for a Cython release at cython/cython#4465

@msullivan
Copy link
Collaborator

This seems great, thank you for the PR. I'm not too worried about not running the 3.11 tests.

@msullivan msullivan merged commit 2b7e2df into python:master Dec 3, 2021
@vstinner vstinner deleted the py_set_type branch December 3, 2021 11:30
@vstinner
Copy link
Member Author

vstinner commented Dec 3, 2021

This seems great, thank you for the PR. I'm not too worried about not running the 3.11 tests.

Thanks for the merge ;-)

tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
"Py_TYPE(t) = metaclass;" fails with a compiler error on Python 3.11:

* https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes
* https://docs.python.org/dev/c-api/structures.html#c.Py_TYPE

* Replace "Py_TYPE(t) = metaclass;" with "Py_SET_TYPE(t, metaclass);"
* Replace "Py_SIZE(self) = newsize;" with "Py_SET_SIZE(self, newsize);"
* Add a copy of pythoncapi_compat.h header to add Py_SET_TYPE() and
  Py_SET_SIZE() functions to Python 3.8 and older:
  https://github.com/pythoncapi/pythoncapi_compat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants