GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `make patchcheck` should check the whitespace of .c/.h files · Issue #53158 · python/cpython

make patchcheck should check the whitespace of .c/.h files #53158

New issue
Copy link
New issue
Copy link
Closed
Closed
make patchcheck should check the whitespace of .c/.h files#53158
Copy link
Labels
buildThe build process and cross-buildThe build process and cross-buildtype-featureA feature request or enhancementA feature request or enhancement

Description

@brettcannon
brettcannon
opened on Jun 6, 2010
Issue body actions
BPO 8912
Nosy @jcea, @abalkin, @pitrou, @vstinner, @ezio-melotti, @merwok, @davidmalcolm, @sandrotosi, @cjerdonek, @serhiy-storchaka
Files
  • refactor.diff: Simple refactoring to support upcoming improvements
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2010-06-06.03:24:37.866>
    labels = ['type-feature']
    title = '`make patchcheck` should check the whitespace of .c/.h files'
    updated_at = <Date 2020-02-03.21:38:44.046>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2020-02-03.21:38:44.046>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2010-06-06.03:24:37.866>
    creator = 'brett.cannon'
    dependencies = []
    files = ['17741']
    hgrepos = []
    issue_num = 8912
    keywords = ['patch', 'needs review']
    message_count = 29.0
    messages = ['107178', '107754', '107762', '107817', '107824', '107831', '107832', '107844', '107849', '107850', '107853', '107854', '107856', '107857', '107861', '107862', '107864', '107865', '108362', '108367', '108369', '109269', '109296', '109302', '109312', '113847', '113848', '113851', '169585']
    nosy_count = 10.0
    nosy_names = ['jcea', 'belopolsky', 'pitrou', 'vstinner', 'ezio.melotti', 'eric.araujo', 'dmalcolm', 'sandro.tosi', 'chris.jerdonek', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'accepted'
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue8912'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    Activity

    Next
    1. brettcannon commented on Jun 6, 2010

      @brettcannon
      brettcannon
      on Jun 6, 2010
      MemberAuthor
      More actions

      This would be especially useful now that only spaces are used in .c/.h files and not tabs.

    2. brettcannon
      added
      type-featureA feature request or enhancementA feature request or enhancement
      on Jun 6, 2010
    3. merwok commented on Jun 13, 2010

      @merwok
      merwok
      on Jun 13, 2010
      Member
      More actions

      Here’s a quick crack at it. Conservative approach: Don’t reindent, just complain.

    4. merwok commented on Jun 13, 2010

      @merwok
      merwok
      on Jun 13, 2010
      Member
      More actions

      Updating patch to check header files too. Untested.

    5. brettcannon commented on Jun 14, 2010

      @brettcannon
      brettcannon
      on Jun 14, 2010
      MemberAuthor
      More actions

      Thanks for the patch, Éric. I will get to it when I can.

    6. brettcannon
      self-assigned this
      on Jun 14, 2010
    7. merwok commented on Jun 14, 2010

      @merwok
      merwok
      on Jun 14, 2010
      Member
      More actions

      I may add that although there is no formal test of any kind, I added tabs in two places in one .c file and in one place in another place, and it correctly reported two files. It’s a small function mostly copied from the one above; the only part where I used my brain is the counter (Python did the rest), so it should be ok.

    8. abalkin commented on Jun 14, 2010

      @abalkin
      abalkin
      on Jun 14, 2010
      Member
      More actions

      Éric,

      It will be helpful if your code could also check for lines longer than 79 characters.

    9. abalkin commented on Jun 14, 2010

      @abalkin
      abalkin
      on Jun 14, 2010
      Member
      More actions

      .. and trailing white space.

    10. merwok commented on Jun 14, 2010

      @merwok
      merwok
      on Jun 14, 2010
      Member
      More actions

      Replacing VCS hooks, are we? :) Updated and attached.

      Ideas for other feature requests:

      • Printing the name of files with issues;
      • Fail-fast mode or full report.
    11. mdickinson commented on Jun 15, 2010

      @mdickinson
      mdickinson
      on Jun 15, 2010
      Member
      More actions

      Nitpick: shouldn't that

      len(line) > 79
      

      be

      len(line) > 80
      

      ? Either that, or strip the line ending from the line before computing its length.

    12. mdickinson commented on Jun 15, 2010

      @mdickinson
      mdickinson
      on Jun 15, 2010
      Member
      More actions

      Similarly, isn't

      line[-1].isspace()

      always going to be true (well, except possibly at the end of the file), thanks to the line-ending character?

    13. merwok commented on Jun 15, 2010

      @merwok
      merwok
      on Jun 15, 2010
      Member
      More actions

      Forgot readling kept the line end, thanks for catching. Updated (yay for Mercurial Queues!)

    14. merwok commented on Jun 15, 2010

      @merwok
      merwok
      on Jun 15, 2010
      Member
      More actions

      s/readling/readline/
      s/readline/iterating over the file/

    15. mdickinson commented on Jun 15, 2010

      @mdickinson
      mdickinson
      on Jun 15, 2010
      Member
      More actions

      Sorry to be nitpicky, but:

      (a) the line[-2] produces "IndexError: string index out of range" on empty
      lines, and

      (b) this won't detect trailing whitespace on the last line of a file, if there's no newline at the end of the file. Actually, it might also be worth checking that there *is* a newline at the end of the file; this is actually required by the C standards. (E.g., C99 5.1.1.2p2: "A source file that is not empty shall end in a new-line character".)

    16. 10 remaining items

    17. abalkin commented on Jul 5, 2010

      @abalkin
      abalkin
      on Jul 5, 2010
      Member
      More actions

      Hmm, it looks like patchcheck does not fix trailing whitespace in c files:

      $ grep ' $' Modules/datetimemodule.c| cat -ve
          $
                         GET_TD_DAYS(offset1) * 86400 - $
                      Py_DECREF(offset);                $
      	    if ((offset1 != offset2) && $
       $
      $ make patchcheck

      Modules/Setup.dist is newer than Modules/Setup;
      check to make sure you have all the updates you
      need in your Modules/Setup file.
      Usually, copying Modules/Setup.dist to Modules/Setup will work.
      -----------------------------------------------
      ./python.exe ./Tools/scripts/patchcheck.py
      Getting the list of files that have been added/changed ... 1 file
      Fixing whitespace ... 0 files
      Docs modified ... NO
      Misc/ACKS updated ... NO
      Misc/NEWS updated ... NO

      Did you run the test suite?

    18. abalkin
      reopened this on Jul 5, 2010
    19. merwok commented on Jul 5, 2010

      @merwok
      merwok
      on Jul 5, 2010
      Member
      More actions

      Sorry if I was unclear. Out of the four points I listed, this patch only did the refactoring (4). I have another patch to add and use a check_pep7 function, I’ll refresh it and post it.

    20. brettcannon commented on Jul 5, 2010

      @brettcannon
      brettcannon
      on Jul 5, 2010
      MemberAuthor
      More actions

      On Sun, Jul 4, 2010 at 22:40, Éric Araujo <[email protected]> wrote:

      Éric Araujo <[email protected]> added the comment:

      Sorry if I was unclear. Out of the four points I listed, this patch only did the refactoring (4). I have another patch to add and use a check_pep7 function, I’ll refresh it and post it.

      You were clear, I just prematurely closed it by accident.

    21. merwok commented on Aug 13, 2010

      @merwok
      merwok
      on Aug 13, 2010
      Member
      More actions

      I wonder how to have sane code reuse between patchcheck and Mercurial hooks. Mark seems to have started seconding Dirkjan with hooks, see e.g.
      http://hg.python.org/hooks/rev/0344575ad60e, so I wonder if we’re going to use only hooks (pro: they will be invoked on every push, whereas patchcheck is opt-in, con: they would require that contributors clone the hooks repo and set them up) or still maintain patchcheck, which has pros (no setup, does not require a VCS) and cons (not automatic, not widely used, whereas hooks can be part of the new python-dev policy).

    22. abalkin commented on Aug 13, 2010

      @abalkin
      abalkin
      on Aug 13, 2010
      Member
      More actions

      Note directly related to this issue, but untabify.py fails on files that contain non-ascii characters. For example:

      $ ./python.exe Tools/scripts/untabify.py Modules/_heapqmodule.c
      Traceback (most recent call last):
          ...
          (result, consumed) = self._buffer_decode(data, self.errors, final)
      UnicodeDecodeError: 'utf8' codec can't decode byte 0xe7 in position 173: invalid continuation byte

      I am not sure what relevant C standard has to say about using non-ascii characters in comments, but the checking tool should not fail with a traceback in such situation.

    23. abalkin commented on Aug 13, 2010

      @abalkin
      abalkin
      on Aug 13, 2010
      Member
      More actions

      I opened bpo-9598 for the untabify bug. For the purposes of source checking, I believe non-ascii characters should be disallowed in python C source code. According to my understanding of C89 standard, interpretation of characters outside of the basic character set is implementation and locale dependent.

    24. brettcannon
      removed their assignment
      on Jun 27, 2011
    25. cjerdonek commented on Aug 31, 2012

      @cjerdonek
      cjerdonek
      on Aug 31, 2012
      Member
      More actions

      The following commit from today is related to this issue: 815b88454e3e

      "Remove trailing whitespace in order to silence warnings on HP-UX."

    26. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    27. iritkatriel
      added
      buildThe build process and cross-buildThe build process and cross-build
      on Oct 26, 2023
    28. StanFromIreland commented on Apr 23, 2025

      @StanFromIreland
      StanFromIreland
      on Apr 23, 2025 · Hidden as resolved
      show commentMore actions
    29. skirpichev commented on Apr 23, 2025

      @skirpichev
      skirpichev
      on Apr 23, 2025
      Member
      More actions

      make patchcheck is still here

    30. hugovk commented on Jun 26, 2025

      @hugovk
      hugovk
      on Jun 26, 2025
      Member
      More actions

      patchcheck.py is still around, but whitespace checks have been removed from it (which doesn't run in CI), and added to pre-commit (run in CI), including .c and .h files.

      We also have a EditorConfig file, I recommend enabling this in your editor.

    31. hugovk
      closed this as completedon Jun 26, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      buildThe build process and cross-buildThe build process and cross-buildtype-featureA feature request or enhancementA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.