Skip to content

Remove trailing white spaces automatically  #935

Closed

Description

@michaelgrund

So far trailing white spaces in files are not automatically detected when running make format, make check and make lint (see #890) .

Do you think we should add such check, if possible, to follow the PEP8 guidelines?

Are you willing to help implement and maintain this feature? Discuss first

Activity

  1. added
    question
    on Feb 19, 2021
  2. seisman commented on Feb 19, 2021

    @seisman
    Member

    I tried the following script (with invisible trailing whitespaces in many lines):

    """
    This is a test.   
    """
    
    def add(x, y):   
        """
        >>> add(5, 4)   
        9   
        """
        # this is a comment   
        return x + y   

    Running black removes all trailing whitespaces for me.

    Not sure why it hehaves differently in #890.

  3. seisman commented on Feb 19, 2021

    @seisman
    Member

    Running black removes all trailing whitespaces for me.

    No, black doesn't remove the trailing whitespace in the docstrings of the file.

  4. maxrjones commented on Feb 19, 2021

    @maxrjones
    Member

    flake8 would check for whitespace and lines >80 (both not caught by black in examples); currently flake8 is only used for pygmt, setup.py, and doc/conf.py.

  5. weiji14 commented on Feb 19, 2021

    @weiji14
    Member

    Running black removes all trailing whitespaces for me.

    No, black doesn't remove the trailing whitespace in the docstrings of the file.

    Does blackdoc not remove the trailing whitespace in the docstrings? Interesting 🤔 Might be worth filing an issue on https://github.com/keewis/blackdoc if we can confirm this.

  6. seisman commented on Feb 19, 2021

    @seisman
    Member

    Does blackdoc not remove the trailing whitespace in the docstrings?

    None of black, blackdoc, and docformatter does to the file-scope docstrings. It's possible these are not "docstrings" https://www.python.org/dev/peps/pep-0257/.

  7. seisman commented on Feb 20, 2021

    @seisman
    Member

    Related issue: psf/black#318

  8. michaelgrund commented on Feb 20, 2021

    @michaelgrund
    MemberAuthor

    Related issue: psf/black#318

    Means it is not possible to do any automatic check and everybody has to care about the spaces before committing, right?

  9. seisman commented on Feb 20, 2021

    @seisman
    Member

    Perhaps docformatter should remove the trailing whitespace? It says:

    docformatter also handles some of the PEP 8 conventions.

    Don't write string literals that rely on significant trailing whitespace. Such trailing whitespace is visually indistinguishable and some editors (or more recently, reindent.py) will trim them.

  10. seisman commented on Feb 20, 2021

    @seisman
    Member

    docformatter can remove trailing whitespaces from the following script:

    """
    A docstring with some invisible whitespace.     
    
    More description with some invisible trailing whitespaces.   
    """
    

    but does nothing to:

    """
    A docstring with some invisible whitespace.     
    =================================================
    
    More description with some invisible trailing whitespaces.   
    """
    

    Reported a bug to docformatter at PyCQA/docformatter#71.

  11. michaelgrund commented on Feb 23, 2021

    @michaelgrund
    MemberAuthor

    docformatter can remove trailing whitespaces from the following script:

    """
    A docstring with some invisible whitespace.     
    
    More description with some invisible trailing whitespaces.   
    """
    

    but does nothing to:

    """
    A docstring with some invisible whitespace.     
    =================================================
    
    More description with some invisible trailing whitespaces.   
    """
    

    Reported a bug to docformatter at myint/docformatter#71.

    Interesting but good to know that we can differentiate between normal scripts and sphinx-gallery style header docstrings.

  12. added
    maintenance
    on Nov 8, 2021
  13. brnt commented on May 28, 2023

    @brnt

    Trailing spaces in docstrings sometimes have syntactical meaning (e.g., forcing a markdown line break). As questionable as it is to have some count of non-printing characters trigger a material document change, we are where we are (and Markdown is extremely prevalent). Stripping those trailing spaces in docstrings could break the formatting of parameter lists in IDE code hints (and probably some other stuff I haven't thought of).

  14. seisman commented on Nov 23, 2023

    @seisman
    Member

    I'm going to close the issue mainly because: (1) it's a minor issue, (2) it does't bother us in the last two years, (3) modern text editors and IDEs have configurations to do it automatically.

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

    maintenancequestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions