Skip to content
Myr

Add type annotations for instance attributes in `formatting`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by jorenham · committed by jorenham · parent 648d7c4 · Browse files · 1 file+11 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−6 removed

  • other:+11 added−6 removed

1 file+11 added−6 removed

modified:src/click/formatting.py+11 added-6 removed
117 unmodified lines
118 :param width: the width for the text. This defaults to the terminal119 width clamped to a maximum of 78.120 """121122 indent_increment: int123 width: int124 current_indent: int125 buffer: list[str]126127 def __init__(128 self,129 indent_increment: int = 2,130 width: int | None = None,
8 unmodified lines
139 width = FORCED_WIDTH140 if width is None:141 width = max(min(shutil.get_terminal_size().columns, max_width) - 2, 50)142 self.width = width138 self.current_indent: int = 0139 self.buffer: list[str] = []143 self.current_indent = 0144 self.buffer = []145146 def write(self, string: str) -> None:147 """Writes a unicode string into the internal buffer."""148 self.buffer.append(string)
78 unmodified lines
227 self.write("\n")228229 def write_dl(230 self,226 rows: cabc.Sequence[tuple[str, str]],231 rows: cabc.Iterable[tuple[str, str]],232 col_max: int = 30,233 col_spacing: int = 2,234 ) -> None:235 """Writes a definition list into the buffer. This is how options
34 unmodified lines
270 else:271 self.write("\n")272273 @contextmanager269 def section(self, name: str) -> cabc.Iterator[None]:274 def section(self, name: str) -> cabc.Generator[None]:275 """Helpful context manager that writes a paragraph, a heading,276 and the indents.277278 :param name: the section name that is written as heading.
6 unmodified lines
285 finally:286 self.dedent()287288 @contextmanager284 def indentation(self) -> cabc.Iterator[None]:289 def indentation(self) -> cabc.Generator[None]:290 """A context manager that increases the indentation."""291 self.indent()292 try:293 yield
4 unmodified lines
298 """Returns the buffer contents."""299 return "".join(self.buffer)300301297def join_options(options: cabc.Sequence[str]) -> tuple[str, bool]:302def join_options(options: cabc.Iterable[str]) -> tuple[str, bool]:303 """Given a list of option strings this joins them in the most appropriate304 way and returns them in the form ``(formatted_string,305 any_prefix_is_slash)`` where the second item in the tuple is a flag that306 indicates if any of the option prefixes was a slash.
14 unmodified lines