Skip to content

Parens of parenthesized context managers are removed in some cases, even when targeting 3.9+ #3572

@yilei

Description

@yilei

Before:

with (
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True
      ),
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
      )
  ):
    pass


with (
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True
      ) as a,
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
      )
  ):
    pass


with (
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True
      ),
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
      ) as b
  ):
    pass


with (
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True
      ),
      mock.patch.object(
          self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
      ),
  ):
    pass

After:

with mock.patch.object(self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True), mock.patch.object(
    self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
):
    pass


with mock.patch.object(
    self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True
) as a, mock.patch.object(
    self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
):
    pass


with (
    mock.patch.object(self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True),
    mock.patch.object(
        self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
    ) as b,
):
    pass


with (
    mock.patch.object(self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True),
    mock.patch.object(
        self.xxx_xxxxxx, "xxxxxxxxxx", autospec=True, return_value="xxxx"
    ),
):
    pass

Playground link.

I'll work on a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?F: parenthesesToo many parentheses, not enough parentheses, and so on.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions