-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-106869: Use new PyMemberDef constant names #106871
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
Conversation
I created this PR with this #!/usr/bin/python3
import sys
import re
encoding = "utf8"
patterns = (
('T_SHORT', 'Py_T_SHORT'),
('T_INT', 'Py_T_INT'),
('T_LONG', 'Py_T_LONG'),
('T_FLOAT', 'Py_T_FLOAT'),
('T_DOUBLE', 'Py_T_DOUBLE'),
('T_STRING', 'Py_T_STRING'),
('T_OBJECT', '_Py_T_OBJECT'),
('T_CHAR', 'Py_T_CHAR'),
('T_BYTE', 'Py_T_BYTE'),
('T_UBYTE', 'Py_T_UBYTE'),
('T_USHORT', 'Py_T_USHORT'),
('T_UINT', 'Py_T_UINT'),
('T_ULONG', 'Py_T_ULONG'),
('T_STRING_INPLACE', 'Py_T_STRING_INPLACE'),
('T_BOOL', 'Py_T_BOOL'),
('T_OBJECT_EX', 'Py_T_OBJECT_EX'),
('T_LONGLONG', 'Py_T_LONGLONG'),
('T_ULONGLONG', 'Py_T_ULONGLONG'),
('T_PYSSIZET', 'Py_T_PYSSIZET'),
('T_NONE', '_Py_T_NONE'),
('READONLY', 'Py_READONLY'),
('PY_AUDIT_READ', 'Py_AUDIT_READ'),
('READ_RESTRICTED', 'Py_AUDIT_READ'),
('PY_WRITE_RESTRICTED', '_Py_WRITE_RESTRICTED'),
('RESTRICTED', '(Py_AUDIT_READ | _Py_WRITE_RESTRICTED)'),
)
patterns = [(re.compile(fr'\b{pattern}\b'), replace)
for pattern, replace in patterns]
patterns.append((re.compile('#include "structmember.h".*$', re.MULTILINE), ''))
def update(filename):
with open(filename, encoding=encoding) as fp:
content = fp.read()
old_content = content
for pattern, replace in patterns:
content = pattern.sub(replace, content)
if content != old_content:
print(f"Update {filename}")
with open(filename, "w", encoding=encoding) as fp:
fp.write(content)
def main():
if len(sys.argv) < 2:
print("usage: update.py filename [filename2 ...]")
sys.exit(1)
for filename in sys.argv[1:]:
update(filename)
if __name__ == "__main__":
main() And the shell command:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it was created by a script, there is no need to read every line for accepting this PR.
Before committing these changes I have questions:
- Why
_Py_T_OBJECT
is underscored? - Why is prefix
Py_
used, but notPY_
?
@encukou designed this API in Python 3.12. If if needs to be changed, maybe it's not too late to change it. I'm fine with But I'm also curious about the fact that _Py_T_OBJECT is private and the only public constant for object has an I would prefer to not switch from By the way, I'm considering to expose these new |
Oh, macOS fails to build: Modules/selectmodule.c:1839:41: error: implicit declaration of function 'offsetof' is invalid in C99 |
I just added stddef.h includes to fix build issues 😁 |
11bef5d
to
0c91ecc
Compare
PR rebased on the main branch to fix merge conflicts. I also added the missing #include for macOS in the select module. |
* Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
0c91ecc
to
8d13210
Compare
Oops, I reverted my changes on |
I also updated Parser/asdl_c.py to update Python/Python-ast.c. |
* Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
Remove '#include "structmember.h"'.
If needed, add <stddef.h> to get offsetof() function.
Replace: