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

Remove trailing white spaces automatically #935

Closed
michaelgrund opened this issue Feb 19, 2021 · 13 comments
Closed

Remove trailing white spaces automatically #935

michaelgrund opened this issue Feb 19, 2021 · 13 comments
Labels
maintenance Boring but important stuff for the core devs question Further information is requested

Comments

@michaelgrund
Copy link
Member

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

@michaelgrund michaelgrund added the question Further information is requested label Feb 19, 2021
@seisman
Copy link
Member

seisman commented Feb 19, 2021

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.

@seisman
Copy link
Member

seisman commented Feb 19, 2021

Running black removes all trailing whitespaces for me.

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

@maxrjones
Copy link
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.

@weiji14
Copy link
Member

weiji14 commented Feb 19, 2021

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.

@seisman
Copy link
Member

seisman commented Feb 19, 2021

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/.

@seisman
Copy link
Member

seisman commented Feb 20, 2021

Related issue: psf/black#318

@michaelgrund
Copy link
Member Author

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?

@seisman
Copy link
Member

seisman commented Feb 20, 2021

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.

@seisman
Copy link
Member

seisman commented Feb 20, 2021

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.

@michaelgrund
Copy link
Member Author

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.

@weiji14 weiji14 added the maintenance Boring but important stuff for the core devs label Nov 8, 2021
@seisman
Copy link
Member

seisman commented Jun 7, 2022

@brnt
Copy link

brnt commented May 28, 2023

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).

@seisman
Copy link
Member

seisman commented Nov 23, 2023

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
Labels
maintenance Boring but important stuff for the core devs question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants