def _parse_source(self, src):
    'Parse a source file, extracting directives from comments.'
    f = moves.StringIO(src)
    defs_start = None
    closing_bracket_lines = set()
    whitespace_lines = set()
    for (tok, _, start, _, line) in tokenize.generate_tokens(f.readline):
        (lineno, col) = start
        if ((defs_start is None) and _CLASS_OR_FUNC_RE.match(line)):
            defs_start = lineno
        if _CLOSING_BRACKETS_RE.match(line):
            closing_bracket_lines.add(lineno)
        elif _WHITESPACE_RE.match(line):
            whitespace_lines.add(lineno)
        elif _DOCSTRING_RE.match(line):
            self._docstrings.add(lineno)
        else:
            if closing_bracket_lines:
                self._adjust_type_comments(closing_bracket_lines, whitespace_lines)
            closing_bracket_lines.clear()
            whitespace_lines.clear()
        if (tok == tokenize.COMMENT):
            matches = list(_DIRECTIVE_RE.finditer(line[col:]))
            is_nested = (bool(matches) and (matches[0].start(0) > 0))
            for m in matches:
                code = line[:col].strip()
                (tool, data) = m.groups()
                open_ended = (not code)
                data = data.strip()
                if (tool == 'type'):
                    self._process_type(lineno, code, data, is_nested)
                elif (tool == 'pytype'):
                    try:
                        self._process_pytype(lineno, data, open_ended)
                    except _DirectiveError as e:
                        self._errorlog.invalid_directive(self._filename, lineno, utils.message(e))
                else:
                    pass
    if closing_bracket_lines:
        self._adjust_type_comments(closing_bracket_lines, whitespace_lines)
    if (defs_start is not None):
        disables = list(self._disables.items())
        disables.append(('Type checking', self._ignore))
        for (name, lineset) in disables:
            lineno = lineset.get_disable_after(defs_start)
            if (lineno is not None):
                self._errorlog.late_directive(self._filename, lineno, name)
Parse a source file, extracting directives from comments.
def _parse_source(self, src):
    
    f = moves.StringIO(src)
    defs_start = None
    closing_bracket_lines = set()
    whitespace_lines = set()
    for (tok, _, start, _, line) in tokenize.generate_tokens(f.readline):
        (lineno, col) = start
        if ((defs_start is None) and _CLASS_OR_FUNC_RE.match(line)):
            defs_start = lineno
        if _CLOSING_BRACKETS_RE.match(line):
            closing_bracket_lines.add(lineno)
        elif _WHITESPACE_RE.match(line):
            whitespace_lines.add(lineno)
        elif _DOCSTRING_RE.match(line):
            self._docstrings.add(lineno)
        else:
            if closing_bracket_lines:
                self._adjust_type_comments(closing_bracket_lines, whitespace_lines)
            closing_bracket_lines.clear()
            whitespace_lines.clear()
        if (tok == tokenize.COMMENT):
            matches = list(_DIRECTIVE_RE.finditer(line[col:]))
            is_nested = (bool(matches) and (matches[0].start(0) > 0))
            for m in matches:
                code = line[:col].strip()
                (tool, data) = m.groups()
                open_ended = (not code)
                data = data.strip()
                if (tool == 'type'):
                    self._process_type(lineno, code, data, is_nested)
                elif (tool == 'pytype'):
                    try:
                        self._process_pytype(lineno, data, open_ended)
                    except _DirectiveError as e:
                        self._errorlog.invalid_directive(self._filename, lineno, utils.message(e))
                else:
                    pass
    if closing_bracket_lines:
        self._adjust_type_comments(closing_bracket_lines, whitespace_lines)
    if (defs_start is not None):
        disables = list(self._disables.items())
        disables.append(('Type checking', self._ignore))
        for (name, lineset) in disables:
            lineno = lineset.get_disable_after(defs_start)
            if (lineno is not None):
                self._errorlog.late_directive(self._filename, lineno, name)