shed-parentheses
FormattingSheds a grouping parenthesis pair that binds nothing, reflowing the expression onto the line it now fits.
Every class on Python 3 inherits from object whether or not the header says so, and a header with no bases at all needs no parentheses to hold the nothing it declares. Both forms put tokens between the reader and the class name that carry no information once they are read.
class C: as the bare declaration the longer spellings already meant.The two forms shed the same way because both leave a base list holding nothing, so the parentheses go with the base rather than standing empty behind it, and a space written between them and the class name goes too. An object sitting beside something real is narrower, in that the base list still has a member to carry, so only the object and the comma binding it to its neighbor go and the parentheses stay to hold what survives. A metaclass= keyword counts as a surviving member the same way a named base does. Where a base carries a grouping pair of its own, that pair goes with it, though
A base named object is only the builtin where the module has not rebound that name ahead of the class, so a module opening object = LegacyBase keeps every header written against it. A comment inside the span that would go holds the header as written too, since removing the span would take the comment with it, and that holds for a comment annotating an object base and one sitting inside an otherwise-empty pair alike.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggles the rule on or off. |
A class written as class C(object): sheds the base and the parentheses that held it, leaving class C:. Every class inherits from object on Python 3, so the written base states what the bare header already says.
class Cache:
def clear(self):
self.entries.clear()
class Registry:
def register(self, name):
self.entries.append(name)
A metaclass= keyword is a surviving member of the base list, so the object ahead of it goes with its comma while the parentheses stay to carry the keyword.
Where the base list spans lines, the object entry goes with the separator on its side, taking the whole line it occupied and leaving the remaining members at the indent they already had.
A header written class C(): carries a base list holding nothing, so both parentheses go and the declaration reads as class C:. A space written between the class name and the parentheses goes with them, leaving no gap ahead of the colon.
Where a base list names something else too, only the object entry and the comma binding it to the preceding base go, so class C(Mapping, object): becomes class C(Mapping): with the parentheses kept.
A comment sitting in the span that would go takes the deletion with it, so a base list carrying one is left as written whether the comment annotates an object base or an empty pair of parentheses.
Where the module rebinds object ahead of the class, the base names that binding rather than the builtin, so the header is left as written.
Sheds a grouping parenthesis pair that binds nothing, reflowing the expression onto the line it now fits.
Removes trailing commas from collections, signatures, calls, and every other bracketed container.
For per-statement opt-outs, the Suppression chapter covers the # prose: skip[shed-redundant-base] directive, which holds every line a wrapped class header spans.