Skip to content

gh-145497: Fix _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES - #151152

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:static_exceptions
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:static_exceptions

Conversation

@vstinner

@vstinner vstinner commented Jun 9, 2026

Copy link
Copy Markdown
Member

The _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES macro is no longer a hardcoded number to reduce the maintenance burden.

  • Add _Py_NUM_STATIC_EXCEPTIONS: size of the static_exceptions array.
  • Add _Py_FOREACH_STATIC_EXTRA_TYPE() to count the number of extra types.

The _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES macro is no longer a
hardcoded number to reduce the maintenance burden.

* Add _Py_NUM_STATIC_EXCEPTIONS: size of the static_exceptions array.
* Add _Py_FOREACH_STATIC_EXTRA_TYPE() to count the number of extra
  types.

Co-authored-by: Donghee Na <donghee.na@python.org>
update one of these numbers.
*/
#define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 120
#define _Py_NUM_STATIC_EXCEPTIONS 69

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you mange the number of _Py_NUM_STATIC_EXCEPTIONS manually, I beleive that this is not what we wanted

If you add a new static type to the standard library, you may have to
update one of these numbers.
*/
#define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 120

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still _Py_NUM_MANAGED_PREINITIALIZED_TYPES is manged by hand.

@corona10

corona10 commented Jun 9, 2026

Copy link
Copy Markdown
Member

My original intention of this issue is that people don't need to care about the actual number of types they need to know.

@vstinner

vstinner commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@corona10:

Still _Py_NUM_MANAGED_PREINITIALIZED_TYPES is manged by hand.

If you had an item to static_types, you get a compiler warning. You get a hint a build time that something is wrong. It should help to detect when _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES is outdated.

@corona10

corona10 commented Jun 9, 2026

Copy link
Copy Markdown
Member

If you had an item to static_types, you get a compiler warning. You get a hint a build time that something is wrong. It should help to detect when _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES is outdated.

Yeah I agree that point, the only problem might be coverage of the solution that we want to cover :)

@vstinner

Copy link
Copy Markdown
Member Author

This approach requires to maintain a hardcoded list of "static extra type" which again can get outdated if a new static type is added. I wrote a different approach which actually counts static types at Python startup to make sure that macros are up to date.

See my new PR gh-157582. I close this one.

@vstinner vstinner closed this Sep 15, 2026
@vstinner
vstinner deleted the static_exceptions branch September 15, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants