Skip to content

PEP 7: Require -Werror=declaration-after-statement #3728

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

Closed
wants to merge 2 commits into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 19, 2024


📚 Documentation preview 📚: https://pep-previews--3728.org.readthedocs.build/

@vstinner
Copy link
Member Author

vstinner commented Mar 19, 2024

Previous requests:

Building Python requires a C11 compiler, but the C API should try to remain as usable as possible: support C99 and partially ISO C90. The C API is no longer strictly compatible with ISO C90, since it uses C99 // comment style.

There are still a few projects using the Python C API or embedding Python which are built with -Werror=declaration-after-statement compiler flag. I suppose that the flag was used 5-10 years ago to catch build errors in advance since MSVC didn't support C99. Today, MSVC supports C11 and so this flag may no longer be relevant. Well, it's cheaper to change 2 lines in the C API per year, rather than arguing if -Werror=declaration-after-statement is strictly required or not.

Before, this rule was unwritten. I propose to write it down.

cc @serhiy-storchaka @colesbury @erlend-aasland

@vstinner
Copy link
Member Author

See also python/cpython#116990 which implements this check on the C API test suite.

@gvanrossum
Copy link
Member

What? Why? Where is the discussion?

@vstinner
Copy link
Member Author

What? Why? Where is the discussion?

The discussion is here. Should it happen somewhere else?

@gvanrossum
Copy link
Member

I feel there needs to be a more public discussion of whether we really need to cramp our style to support some projects that still use a 30-year-old C dialect. Pointing to a few closed issues does not form a discussion IMO.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

This is not an endorsement of the requirement, but a clarification -- I had originally read it as a requirement that we build something with C90. I also clarify that this only affects inline functions in public headers.

Nevertheless I am still against this PEP change, I think those old projects should do some work if they want to link with the latest CPython. The rule is also useless unless there's a CI build action that points out violations of this rule.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
@vstinner
Copy link
Member Author

This is not an endorsement of the requirement, but a clarification -- I had originally read it as a requirement that we build something with C90. I also clarify that this only affects inline functions in public headers.

Sorry, my sentence was misleading. Your sentence is way better :-)

The rule is also useless unless there's a CI build action that points out violations of this rule.

As written previously, I just added test_cext which implements this check (I wrote it for other checks).

If we change this "unwritten" rule, I can just remove the CI check, but it might be good to have such check in 3.11 and 3.12 branches to not change the "status quo" of stable versions. Moreover, 3.12 was already fixed (it was just 2 lines).

@gvanrossum
Copy link
Member

So what would need to be changed in main? Do you have a draft PR?

This would have been easier if you had obtained consensus elsewhere instead of just in your own head. :-)

@vstinner
Copy link
Member Author

So what would need to be changed in main?

There is no further changes planned. This change only proposes to require fixing future issues with -Werror=declaration-after-statement.

@vstinner
Copy link
Member Author

I looked further in history to try to identify the number of impacted projects.

But none of these changes mention any project name, only "third-party code".

In short, I only found 3 projects: PostgreSQL, Xen and onboard.

I think the best explanation can be found in this comment in 2022 by @petere (emphasis in mine):

PostgreSQL is another package that uses -Wdeclaration-after-statement and as a consequence occasionally runs afoul of Python header files. As you say, it's not a technical requirement but more a desire to maintain a consistent style from the before-C99 days. Maybe this is a battle we (PostgreSQL) will lose some day, but in the meantime, poking the Python devs once a year is less work then re-litigating the code style choice among the PostgreSQL devs. ;-)

@serhiy-storchaka: Do you want to continue this tradition to stay compatible with -Werror=declaration-after-statement? I'm asking you, since you approved most changes to fix issues with this flag.

Is it worth it? For a product as big as PostgreSQL, it can be hard to change their policy. On the Python side, it's usually about changing 2 lines per year.

@colesbury
Copy link
Contributor

PostgreSQL, xen, and Linux already changed their code. They no longer compile Python.h with -Werror=declaration-after-statement

@vstinner
Copy link
Member Author

Honestly, if Linux, PostgreSQL and Xen stopped using the flag, I don't think that we should still care about it. It becomes more and more annoying since the Python C API has more and more static inline functions.

So I wrote PR #3734 to write down that we supported this flag, but we stop supporting it. I'm not sure if it's worth it to mention it explicitly.

I close this issue.

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.

3 participants