Pytype accepts directives in the form of python comments, both typecomments like
x =  # type: List[int]
and error disabling
x = f(a, b) # pytype: disable=wrong-arg-types
We also support range-based disabling:
# pytype: disable=attribute-error
# pytype: enable=attribute-error
Since the main pytype loop operates on bytecode, which does not contain comments, we have a preprocessing pass to collect these comments and later merge them with the corresponding line numbers in the bytecode.
directors.py defines a
Director class, which scans a source file line by
line, extracting and storing source level information for the main
to use when analysing the program.
Note: The Director is also the best place to collect other information that needs
access to the source code rather than the bytecode, e.g. variable annotations,
class and method decorators, and docstrings. See
Director.__init__ for a full
list of all the data collected.
The Director is instantiated at the start of the main loop, in
vm.py/VirtualMachine::run_program(). The rest of the code uses the director in
director.annotations, all of which are indexed by line number
director.filter_error() to check if an error has been disabled
The latter method is needed because error disabling is range based, so checking
is not as simple as
if line_number in director.disables.