MCPcopy Index your code
hub / github.com/python/mypy / add_error_info

Method add_error_info

mypy/errors.py:769–837  ·  view source on GitHub ↗
(self, info: ErrorInfo, *, file: str | None = None)

Source from the content-addressed store, hash-verified

767 return any(w.on_error(file, info) for w in self.get_watchers())
768
769 def add_error_info(self, info: ErrorInfo, *, file: str | None = None) -> None:
770 lines = info.origin_span
771 file = file or self.file
772 # process the stack of ErrorWatchers before modifying any internal state
773 # in case we need to filter out the error entirely
774 # NB: we need to do this both here and in _add_error_info, otherwise we
775 # might incorrectly update the sets of ignored or only_once messages
776 if self._filter_error(file, info):
777 return
778 if not info.blocker: # Blockers cannot be ignored
779 if file in self.ignored_lines:
780 # Check each line in this context for "type: ignore" comments.
781 # line == end_line for most nodes, so we only loop once.
782 for scope_line in lines:
783 if self.is_ignored_error(scope_line, info, self.ignored_lines[file]):
784 err_code = info.code or codes.MISC
785 if not self.is_error_code_enabled(err_code):
786 # Error code is disabled - don't mark the current
787 # "type: ignore" comment as used.
788 return
789 # Annotation requests us to ignore all errors on this line.
790 self.used_ignored_lines[file][scope_line].append(err_code.code)
791 return
792 if file in self.ignored_files:
793 return
794 if info.only_once:
795 if info.message in self.only_once_messages:
796 return
797 self.only_once_messages.add(info.message)
798 if (
799 self.seen_import_error
800 and info.code not in (IMPORT, IMPORT_UNTYPED, IMPORT_NOT_FOUND)
801 and self.has_many_errors()
802 ):
803 # Missing stubs can easily cause thousands of errors about
804 # Any types, especially when upgrading to mypy 0.900,
805 # which no longer bundles third-party library stubs. Avoid
806 # showing too many errors to make it easier to see
807 # import-related errors.
808 info.hidden = True
809 self.report_hidden_errors(file, info)
810 self._add_error_info(file, info)
811 ignored_codes = self.ignored_lines.get(file, {}).get(info.line, [])
812 if ignored_codes and info.code:
813 # Something is ignored on the line, but not this error, so maybe the error
814 # code is incorrect.
815 msg = f"""Error code "{info.code.code}" not covered by "type: ignore[{', '.join(ignored_codes)}]" comment"""
816 if info.code in original_error_codes:
817 # If there seems to be a "type: ignore" with a stale error
818 # code, report a more specific note.
819 old_code = original_error_codes[info.code].code
820 if old_code in ignored_codes:
821 msg = (
822 f'Error code changed to {info.code.code}; "type: ignore" comment '
823 + "may be out of date"
824 )
825 self.note_for_info(file, info, msg, None, only_once=False)
826 if (

Callers 4

reportMethod · 0.95
add_errorsMethod · 0.80
load_statesFunction · 0.80
reprocess_nodesFunction · 0.80

Calls 11

_filter_errorMethod · 0.95
is_ignored_errorMethod · 0.95
is_error_code_enabledMethod · 0.95
has_many_errorsMethod · 0.95
report_hidden_errorsMethod · 0.95
_add_error_infoMethod · 0.95
note_for_infoMethod · 0.95
appendMethod · 0.80
addMethod · 0.45
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected