Update textwrap stubs (#1634)

This commit adds a few missing return types to the Python 3 textwrap
stubs and fleshes out the Python 2 textwrap stubs so they're on par with
the Python 3 version.

This change:

1.  Changes the order of the arguments in Python 2 and Python 3
    to match the order from the source code instead of the
    documentation.

2.  Adds other undocumented attributes besides whitespace_trans
    (for consistency).

3.  Moves the '*' argument in TextWrapper.__init__ for Python 3
    to match the source code.

4.  Made function stub formatting consistent with typeshed style
    conventions.
This commit is contained in:
Michael Lee
2017-10-08 21:12:20 -07:00
committed by Jelle Zijlstra
parent 6a55ad5b60
commit 51829c1bc8
2 changed files with 108 additions and 83 deletions

View File

@@ -1,64 +1,55 @@
# Better textwrap stubs hand-written by o11c.
# https://docs.python.org/3/library/textwrap.html
from typing import (
Callable,
List,
)
from typing import Callable, List, Optional, Dict, Pattern
class TextWrapper:
width: int = ...
initial_indent: str = ...
subsequent_indent: str = ...
expand_tabs: bool = ...
replace_whitespace: bool = ...
fix_sentence_endings: bool = ...
drop_whitespace: bool = ...
break_long_words: bool = ...
break_on_hyphens: bool = ...
tabsize: int = ...
max_lines: Optional[int] = ...
placeholder: str = ...
# Attributes not present in documentation
sentence_end_re: Pattern[str] = ...
wordsep_re: Pattern[str] = ...
wordsep_simple_re: Pattern[str] = ...
whitespace_trans: str = ...
unicode_whitespace_trans: Dict[int, int] = ...
uspace: int = ...
x: int = ...
def __init__(
self,
width: int = ...,
*,
initial_indent: str = ...,
subsequent_indent: str = ...,
expand_tabs: bool = ...,
tabsize: int = ...,
replace_whitespace: bool = ...,
fix_sentence_endings: bool = ...,
break_long_words: bool = ...,
break_on_hyphens: bool = ...,
drop_whitespace: bool = ...,
max_lines: int = ...,
placeholder: str = ...
) -> None:
self.width = width
self.initial_indent = initial_indent
self.subsequent_indent = subsequent_indent
self.expand_tabs = expand_tabs
self.tabsize = tabsize
self.replace_whitespace = replace_whitespace
self.fix_sentence_endings = fix_sentence_endings
self.break_long_words = break_long_words
self.break_on_hyphens = break_on_hyphens
self.drop_whitespace = drop_whitespace
self.max_lines = max_lines
self.placeholder = placeholder
self,
width: int = ...,
initial_indent: str = ...,
subsequent_indent: str = ...,
expand_tabs: bool = ...,
replace_whitespace: bool = ...,
fix_sentence_endings: bool = ...,
break_long_words: bool = ...,
drop_whitespace: bool = ...,
break_on_hyphens: bool = ...,
tabsize: int = ...,
*,
max_lines: Optional[int] = ...,
placeholder: str = ...) -> None:
...
# Private methods *are* part of the documented API for subclasses.
def _munge_whitespace(self, text: str) -> str:
...
def _munge_whitespace(self, text: str) -> str: ...
def _split(self, text: str) -> List[str]: ...
def _fix_sentence_endings(self, chunks: List[str]) -> None: ...
def _handle_long_word(self, reversed_chunks: List[str], cur_line: List[str], cur_len: int, width: int) -> None: ...
def _wrap_chunks(self, chunks: List[str]) -> List[str]: ...
def _split_chunks(self, text: str) -> List[str]: ...
def _split(self, text: str) -> List[str]:
...
def _fix_sentence_endings(self, chunks: List[str]) -> None:
...
def _handle_long_word(self, reversed_chunks: List[str], cur_line: List[str], cur_len: int, width: int) -> None:
...
def _wrap_chunks(self, chunks: List[str]) -> List[str]:
...
def _split_chunks(self, text: str) -> List[str]:
...
def wrap(self, text: str) -> List[str]:
...
def fill(self, text: str) -> str:
...
def wrap(self, text: str) -> List[str]: ...
def fill(self, text: str) -> str: ...
def wrap(
@@ -94,7 +85,7 @@ def fill(
drop_whitespace: bool = ...,
max_lines: int = ...,
placeholder: str = ...
):
) -> str:
...
def shorten(
@@ -112,7 +103,7 @@ def shorten(
drop_whitespace: bool = ...,
# Omit `max_lines: int = None`, it is forced to 1 here.
placeholder: str = ...
):
) -> str:
...
def dedent(text: str) -> str: