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

C API: Remove Include/errcode.h header file #107162

Closed
vstinner opened this issue Jul 23, 2023 · 5 comments
Closed

C API: Remove Include/errcode.h header file #107162

vstinner opened this issue Jul 23, 2023 · 5 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Jul 23, 2023

Constants exported by the <errcode.h> header file cannot be used outside Python internals. There is no public C API to tokenize a Python source file. I propose to simply remove this header file (move it to the internal C API). It's not included by Python.h.

In Python 3.12, I removed <token.h > header file: see issue #92651.

In Python 3.10, I removed the C API related to AST and the parser, since it was not possible to use it outside Python internals. See: https://docs.python.org/dev/whatsnew/3.10.html#id4

Linked PRs

@vstinner vstinner added type-feature A feature request or enhancement topic-C-API labels Jul 23, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Jul 23, 2023
Rename Include/errcode.h to Include/internal/pycore_errcode.h.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 23, 2023
Rename Include/errcode.h to Include/internal/pycore_errcode.h.
@serhiy-storchaka
Copy link
Member

It is the part of the C API. See PyRun_InteractiveOneFlags() documentation.

@vstinner
Copy link
Member Author

https://docs.python.org/dev/c-api/veryhigh.html#c.PyRun_InteractiveOneFlags

Oh! I looked for errcode.h usage and I couldn't find it. Thanks for pointing me to this function.

I didn't know that these constants are not only used by the tokenizer, but also by the "high-level" API.

Maybe we should just better document this header file. One concern is that constant names are not prefixed by Py_ or PY_. But since it's not included by Python, maybe it's not really an issue.

vstinner added a commit to vstinner/cpython that referenced this issue Jul 24, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Jul 24, 2023
vstinner added a commit that referenced this issue Jul 24, 2023
Public and documented PyRun_InteractiveOneFlags() C API uses it.
jtcave pushed a commit to jtcave/cpython that referenced this issue Jul 24, 2023
Public and documented PyRun_InteractiveOneFlags() C API uses it.
@vstinner
Copy link
Member Author

I close this issue which is wrong: the <errcode.h> header file is part of the Python C API and used by public PyRun_InteractiveOneFlags() function. I wrote it directly the header file for future readers: 7516953

carljm added a commit to carljm/cpython that referenced this issue Jul 24, 2023
* main: (73 commits)
  Thoroughly refactor the cases generator (python#107151)
  Docs: Add missing markup to Argument Clinic docs (python#106876)
  pythongh-107162: Document errcode.h usage in its comment (python#107177)
  pythongh-106320: Remove private _PyDict C API (python#107145)
  Fix PyVectorcall_Function doc versionadded (python#107140)
  Docs: Remove duplicate word in Argument Clinic howto heading (python#107169)
  pythongh-107017: Change Chapter Strings to Texts in the Introduction chapter. (python#107104)
  pythongh-106320: Remove private _PyObject C API (python#107159)
  Docs: fix typo in os.pwrite docstring (python#107087)
  pythongh-105291: Add link to migration guide for distutils (python#107130)
  pythongh-106948: Docs: Disable links for C standard library functions, OS utility functions and system calls (python#107062)
  pythongh-106320: Remove _PyBytes_Join() C API (python#107144)
  pythongh-106320: Remove private _PyObject C API (python#107147)
  pythongh-106320: Remove _PyTuple_MaybeUntrack() C API (python#107143)
  pythongh-106320: Remove _PyIsSelectable_fd() C API (python#107142)
  Remove superflous whitespaces in `layout.html`. (pythonGH-107067)
  pythongh-107122: Update what's news for dbm.*dbm.clear() method (pythongh-107135)
  pythongh-107122: Add clear method to dbm.ndbm module (pythongh-107126)
  pythongh-62519: Make pgettext search plurals when translation is not found (python#107118)
  pythongh-107122: Add clear method to dbm.gdbm.module (pythongh-107127)
  ...
@serhiy-storchaka
Copy link
Member

I am sure that you can use PyRun_InteractiveOneFlags() even without errcode.h. But if you want to get more details about parsing error, you can include errcode.h.

Since PyRun_InteractiveOneFlags() can also return -1 and set an exception, we perhaps can get rid of these error codes and turn them into appropriate Python exceptions. errcode.h then became obsolete.

@vstinner
Copy link
Member Author

Since PyRun_InteractiveOneFlags() can also return -1 and set an exception, we perhaps can get rid of these error codes and turn them into appropriate Python exceptions. errcode.h then became obsolete.

Well, if you want to try that, you can propose a change :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants