module documentation
(source)

Utility functions with no non-trivial dependencies.
Class ​Decode​Error Exception raised when a file cannot be decoded due to an unknown encoding type.
Class ​Fancy​Formatter Apply color and bold font to terminal output.
Class ​Id​Mapper Generate integer ids for objects.
Function check​_python​_version Report issues with the Python used to run mypy, dmypy, or stubgen
Function correct​_relative​_import Undocumented
Function count​_stats Count total number of errors and files in error list.
Function decode​_python​_encoding Read the Python file with while obeying PEP-263 encoding detection.
Function find​_python​_encoding PEP-263 for detecting Python file encoding
Function get​_class​_descriptors Undocumented
Function get​_mypy​_comments Undocumented
Function get​_prefix Drop the final component of a qualified name (e.g. ('x.y' -> 'x').
Function get​_terminal​_width Get current terminal width if possible, otherwise return the default one.
Function get​_top​_two​_prefixes Return one and two component prefixes of a fully qualified name.
Function get​_unique​_redefinition​_name Get a simple redefinition name not present among existing.
Function hard​_exit Kill the current process without fully cleaning up.
Function hash​_digest Compute a hash digest of some data.
Function is​_stub​_package​_file Undocumented
Function is​_sub​_path Given two paths, return if path1 is a sub-path of path2.
Function is​_typeshed​_file Undocumented
Function module​_prefix Undocumented
Function parse​_gray​_color Reproduce a gray color in ANSI escape sequence
Function read​_py​_file Try reading a Python file as list of source lines.
Function replace​_object​_state Copy state of old node to the new node.
Function short​_type Return the last component of the type name of an object.
Function soft​_wrap Wrap a long error message into few lines.
Function split​_module​_names Return the module and all parent module names.
Function split​_target Undocumented
Function split​_words Split line of text into words (but not within quoted groups).
Function trim​_source​_line Trim a line of source code to fit into max_len.
Function try​_find​_python2​_interpreter Undocumented
Function unmangle Remove internal suffixes from a short name.
Function unnamed​_function Undocumented
Function write​_junit​_xml Undocumented
Constant CURSES​_ENABLED Undocumented
Constant DEFAULT​_COLUMNS Undocumented
Constant default​_python2​_interpreter Undocumented
Constant DEFAULT​_SOURCE​_OFFSET Undocumented
Constant ENCODING​_RE Undocumented
Constant ERROR​_TEMPLATE Undocumented
Constant FAIL​_TEMPLATE Undocumented
Constant fields​_cache Undocumented
Constant MINIMUM​_WIDTH Undocumented
Constant MINIMUM​_WINDOWS​_BUILD​_VT100 Undocumented
Constant MINIMUM​_WINDOWS​_MAJOR​_VT100 Undocumented
Constant PASS​_TEMPLATE Undocumented
Constant T Undocumented
Variable _python2​_interpreter Undocumented
def check_python_version(program): (source)
Report issues with the Python used to run mypy, dmypy, or stubgen
Parameters
program:strUndocumented
def correct_relative_import(cur_mod_id, relative, target, is_cur_package_init_file): (source)

Undocumented

Parameters
cur​_mod​_id:strUndocumented
relative:intUndocumented
target:strUndocumented
is​_cur​_package​_init​_file:boolUndocumented
Returns
Tuple[str, bool]Undocumented
def count_stats(errors): (source)
Count total number of errors and files in error list.
Parameters
errors:List[str]Undocumented
Returns
Tuple[int, int]Undocumented
def decode_python_encoding(source, pyversion): (source)

Read the Python file with while obeying PEP-263 encoding detection.

Returns the source as a string.

Parameters
source:bytesUndocumented
pyversion:Tuple[int, int]Undocumented
Returns
strUndocumented
def find_python_encoding(text, pyversion): (source)
PEP-263 for detecting Python file encoding
Parameters
text:bytesUndocumented
pyversion:Tuple[int, int]Undocumented
Returns
Tuple[str, int]Undocumented
def get_class_descriptors(cls): (source)

Undocumented

Returns
Sequence[str]Undocumented
def get_mypy_comments(source): (source)

Undocumented

Parameters
source:strUndocumented
Returns
List[Tuple[int, str]]Undocumented
def get_prefix(fullname): (source)
Drop the final component of a qualified name (e.g. ('x.y' -> 'x').
Parameters
fullname:strUndocumented
Returns
strUndocumented
def get_terminal_width(): (source)
Get current terminal width if possible, otherwise return the default one.
Returns
intUndocumented
def get_top_two_prefixes(fullname): (source)

Return one and two component prefixes of a fully qualified name.

Given 'a.b.c.d', return ('a', 'a.b').

If fullname has only one component, return (fullname, fullname).

Parameters
fullname:strUndocumented
Returns
Tuple[str, str]Undocumented
def get_unique_redefinition_name(name, existing): (source)

Get a simple redefinition name not present among existing.

For example, for name 'foo' we try 'foo-redefinition', 'foo-redefinition2', 'foo-redefinition3', etc. until we find one that is not in existing.

Parameters
name:strUndocumented
existing:Container[str]Undocumented
Returns
strUndocumented
def hard_exit(status=0): (source)

Kill the current process without fully cleaning up.

This can be quite a bit faster than a normal exit() since objects are not freed.

Parameters
status:intUndocumented
def hash_digest(data): (source)

Compute a hash digest of some data.

We use a cryptographic hash because we want a low probability of accidental collision, but we don't really care about any of the cryptographic properties.

Parameters
data:bytesUndocumented
Returns
strUndocumented
def is_stub_package_file(file): (source)

Undocumented

Parameters
file:strUndocumented
Returns
boolUndocumented
def is_sub_path(path1, path2): (source)
Given two paths, return if path1 is a sub-path of path2.
Parameters
path1:strUndocumented
path2:strUndocumented
Returns
boolUndocumented
def is_typeshed_file(file): (source)

Undocumented

Parameters
file:strUndocumented
Returns
boolUndocumented
def module_prefix(modules, target): (source)

Undocumented

Parameters
modules:Iterable[str]Undocumented
target:strUndocumented
Returns
Optional[str]Undocumented
def parse_gray_color(cup): (source)
Reproduce a gray color in ANSI escape sequence
Parameters
cup:bytesUndocumented
Returns
strUndocumented
def read_py_file(path, read, pyversion): (source)

Try reading a Python file as list of source lines.

Return None if something goes wrong.

Parameters
path:strUndocumented
read:Callable[[str], bytes]Undocumented
pyversion:Tuple[int, int]Undocumented
Returns
Optional[List[str]]Undocumented
def replace_object_state(new, old, copy_dict=False): (source)

Copy state of old node to the new node.

This handles cases where there is __dict__ and/or attribute descriptors (either from slots or because the type is defined in a C extension module).

Assume that both objects have the same __class__.

Parameters
new:objectUndocumented
old:objectUndocumented
copy​_dict:boolUndocumented
def short_type(obj): (source)

Return the last component of the type name of an object.

If obj is None, return 'nil'. For example, if obj is 1, return 'int'.

Parameters
obj:objectUndocumented
Returns
strUndocumented
def soft_wrap(msg, max_len, first_offset, num_indent=0): (source)

Wrap a long error message into few lines.

Breaks will only happen between words, and never inside a quoted group (to avoid breaking types such as "Union[int, str]"). The 'first_offset' is the width before the start of first line.

Pad every next line with 'num_indent' spaces. Every line will be at most 'max_len' characters, except if it is a single word or quoted group.

For example:
first_offset
path/to/file: error: 58: Some very long error message
that needs to be split in separate lines. "Long[Type, Names]" are never split.

^^^^-------------------------------------------------- num_indent max_len

Parameters
msg:strUndocumented
max​_len:intUndocumented
first​_offset:intUndocumented
num​_indent:intUndocumented
Returns
strUndocumented
def split_module_names(mod_name): (source)

Return the module and all parent module names.

So, if mod_name is 'a.b.c', this function will return ['a.b.c', 'a.b', and 'a'].

Parameters
mod​_name:strUndocumented
Returns
List[str]Undocumented
def split_target(modules, target): (source)

Undocumented

Parameters
modules:Iterable[str]Undocumented
target:strUndocumented
Returns
Optional[Tuple[str, str]]Undocumented
def split_words(msg): (source)
Split line of text into words (but not within quoted groups).
Parameters
msg:strUndocumented
Returns
List[str]Undocumented
def trim_source_line(line, max_len, col, min_width): (source)

Trim a line of source code to fit into max_len.

Show 'min_width' characters on each side of 'col' (an error location). If either start or end is trimmed, this is indicated by adding '...' there. A typical result looks like this:

...some_variable = function_to_call(one_arg, other_arg) or...

Return the trimmed string and the column offset to to adjust error location.

Parameters
line:strUndocumented
max​_len:intUndocumented
col:intUndocumented
min​_width:intUndocumented
Returns
Tuple[str, int]Undocumented
def try_find_python2_interpreter(): (source)

Undocumented

Returns
Optional[str]Undocumented
def unmangle(name): (source)
Remove internal suffixes from a short name.
Parameters
name:strUndocumented
Returns
strUndocumented
def unnamed_function(name): (source)

Undocumented

Parameters
name:Optional[str]Undocumented
Returns
boolUndocumented
def write_junit_xml(dt, serious, messages, path, version, platform): (source)

Undocumented

Parameters
dt:floatUndocumented
serious:boolUndocumented
messages:List[str]Undocumented
path:strUndocumented
version:strUndocumented
platform:strUndocumented
CURSES_ENABLED: bool = (source)

Undocumented

Value
False
DEFAULT_COLUMNS: int = (source)

Undocumented

Value
80
default_python2_interpreter: list[str] = (source)

Undocumented

Value
['python2', 'python', '/usr/bin/python', 'C:\\Python27\\python.exe']
DEFAULT_SOURCE_OFFSET: int = (source)

Undocumented

Value
4
ENCODING_RE = (source)

Undocumented

Value
re.compile(rb'([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w\.]+)')
ERROR_TEMPLATE: str = (source)

Undocumented

Value
'''<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="1" failures="0" name="mypy" skips="0" tests="1" time="{time:.
3f}">
  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}"
 time="{time:.3f}">
    <error message="mypy produced errors">{text}</error>
  </testcase>
...
FAIL_TEMPLATE: str = (source)

Undocumented

Value
'''<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="1" name="mypy" skips="0" tests="1" time="{time:.
3f}">
  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}"
 time="{time:.3f}">
    <failure message="mypy produced messages">{text}</failure>
  </testcase>
...
fields_cache: Dict[Type[object], List[str]] = (source)

Undocumented

Value
{}
MINIMUM_WIDTH: int = (source)

Undocumented

Value
20
MINIMUM_WINDOWS_BUILD_VT100: int = (source)

Undocumented

Value
10586
MINIMUM_WINDOWS_MAJOR_VT100: int = (source)

Undocumented

Value
10
PASS_TEMPLATE: str = (source)

Undocumented

Value
'''<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" name="mypy" skips="0" tests="1" time="{time:.
3f}">
  <testcase classname="mypy" file="mypy" line="1" name="mypy-py{ver}-{platform}"
 time="{time:.3f}">
  </testcase>
</testsuite>
...

Undocumented

Value
TypeVar('T')
_python2_interpreter: Optional[str] = (source)

Undocumented