Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

D202: Incompatibility with black 23 #627

Open
adamjstewart opened this issue Feb 1, 2023 · 2 comments
Open

D202: Incompatibility with black 23 #627

adamjstewart opened this issue Feb 1, 2023 · 2 comments

Comments

@adamjstewart
Copy link

Black 23.1.0 introduces a new formatting change that requires an empty line before functions: psf/black#3302. In some rare cases, this seems to counteract pydocstyle requirements.

Steps to reproduce

  1. Create the following file:
    """Foo."""
    
    
    def foo():
        """Foo."""
        # Closure
        def bar():
            """Bar."""
            pass
  2. Run pydocstyle, see that it passes
  3. Run black, see that it inserts a newline before the comment
    --- foo.py	2023-02-01 22:01:42.684243 +0000
    +++ foo.py	2023-02-01 22:02:23.613704 +0000
    @@ -1,9 +1,10 @@
     """Foo."""
    
    
     def foo():
         """Foo."""
    +
         # Closure
         def bar():
             """Bar."""
             pass
  4. Run pydocstyle again, see that it fails:
     foo.py:5 in public function `foo`:
            D202: No blank lines allowed after function docstring (found 1)
    

It's unclear to me whether black or pydocstyle is in the wrong here. Since black is a bigger project, I thought I'd start here and see whether pydocstyle should conform to this new standard set by black or whether this is a bug I should report to black.

@adamjstewart
Copy link
Author

Note that the issue disappears if the comment is removed. Black still reformats the function, but pydocstyle is okay with it with or without the newline. This leads me to believe this is a problem with pydocstyle.

@paravoid
Copy link

I'm facing the same issue. AIUI this was previously raised with #361 and addressed with #426.

The fix had this:

re(r"\s+(?:(?:class|def)\s|@)").match(after)

...and I think the comment seems to just confuse the regexp parser.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants