MCPcopy
hub / github.com/python/mypy / MessageBuilder

Class MessageBuilder

mypy/messages.py:163–2597  ·  view source on GitHub ↗

Helper class for reporting type checker error messages with parameters. The methods of this class need to be provided with the context within a file; the errors member manages the wider context. IDEA: Support a 'verbose mode' that includes full information about types in erro

Source from the content-addressed store, hash-verified

161
162
163class MessageBuilder:
164 """Helper class for reporting type checker error messages with parameters.
165
166 The methods of this class need to be provided with the context within a
167 file; the errors member manages the wider context.
168
169 IDEA: Support a 'verbose mode' that includes full information about types
170 in error messages and that may otherwise produce more detailed error
171 messages.
172 """
173
174 # Report errors using this instance. It knows about the current file and
175 # import context.
176 errors: Errors
177
178 modules: dict[str, MypyFile]
179
180 # Hack to deduplicate error messages from union types
181 _disable_type_names: list[bool]
182
183 def __init__(self, errors: Errors, modules: dict[str, MypyFile]) -> None:
184 self.errors = errors
185 self.options = errors.options
186 self.modules = modules
187 self._disable_type_names = []
188
189 #
190 # Helpers
191 #
192
193 def filter_errors(
194 self,
195 *,
196 filter_errors: bool | Callable[[str, ErrorInfo], bool] = True,
197 save_filtered_errors: bool = False,
198 filter_deprecated: bool = False,
199 filter_revealed_type: bool = False,
200 ) -> ErrorWatcher:
201 return ErrorWatcher(
202 self.errors,
203 filter_errors=filter_errors,
204 save_filtered_errors=save_filtered_errors,
205 filter_deprecated=filter_deprecated,
206 filter_revealed_type=filter_revealed_type,
207 )
208
209 def add_errors(self, errors: list[ErrorInfo]) -> None:
210 """Add errors in messages to this builder."""
211 for info in errors:
212 self.errors.add_error_info(info)
213
214 @contextmanager
215 def disable_type_names(self) -> Iterator[None]:
216 self._disable_type_names.append(True)
217 try:
218 yield
219 finally:
220 self._disable_type_names.pop()

Callers 4

__init__Method · 0.90
__init__Method · 0.90
tokenizer_format_callFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…