Processes a file and holds state. This processes a file by generating tokens, logical and physical lines, and AST trees. This also provides a way of passing state about the file to checks expecting that state. Any public attribute on this object can be requested by a plugin. The kno
| 29 | |
| 30 | |
| 31 | class FileProcessor: |
| 32 | """Processes a file and holds state. |
| 33 | |
| 34 | This processes a file by generating tokens, logical and physical lines, |
| 35 | and AST trees. This also provides a way of passing state about the file |
| 36 | to checks expecting that state. Any public attribute on this object can |
| 37 | be requested by a plugin. The known public attributes are: |
| 38 | |
| 39 | - :attr:`blank_before` |
| 40 | - :attr:`blank_lines` |
| 41 | - :attr:`checker_state` |
| 42 | - :attr:`indent_char` |
| 43 | - :attr:`indent_level` |
| 44 | - :attr:`line_number` |
| 45 | - :attr:`logical_line` |
| 46 | - :attr:`max_line_length` |
| 47 | - :attr:`max_doc_length` |
| 48 | - :attr:`multiline` |
| 49 | - :attr:`noqa` |
| 50 | - :attr:`previous_indent_level` |
| 51 | - :attr:`previous_logical` |
| 52 | - :attr:`previous_unindented_logical_line` |
| 53 | - :attr:`tokens` |
| 54 | - :attr:`file_tokens` |
| 55 | - :attr:`total_lines` |
| 56 | - :attr:`verbose` |
| 57 | """ |
| 58 | |
| 59 | #: always ``False``, included for compatibility |
| 60 | noqa = False |
| 61 | |
| 62 | def __init__( |
| 63 | self, |
| 64 | filename: str, |
| 65 | options: argparse.Namespace, |
| 66 | lines: list[str] | None = None, |
| 67 | ) -> None: |
| 68 | """Initialize our file processor. |
| 69 | |
| 70 | :param filename: Name of the file to process |
| 71 | """ |
| 72 | self.options = options |
| 73 | self.filename = filename |
| 74 | self.lines = lines if lines is not None else self.read_lines() |
| 75 | self.strip_utf_bom() |
| 76 | |
| 77 | # Defaults for public attributes |
| 78 | #: Number of preceding blank lines |
| 79 | self.blank_before = 0 |
| 80 | #: Number of blank lines |
| 81 | self.blank_lines = 0 |
| 82 | #: Checker states for each plugin? |
| 83 | self._checker_states: dict[str, dict[Any, Any]] = {} |
| 84 | #: Current checker state |
| 85 | self.checker_state: dict[Any, Any] = {} |
| 86 | #: User provided option for hang closing |
| 87 | self.hang_closing = options.hang_closing |
| 88 | #: Character used for indentation |
nothing calls this directly
no outgoing calls
no test coverage detected