pytorch/torch/_export/db/logging.py
Maggie Moss 4ab847bbc7 Pyrefly suppressions 4/n (#164615)
Adds suppressions to pyrefly will typecheck clean: https://github.com/pytorch/pytorch/issues/163283

Test plan:
dmypy restart && python3 scripts/lintrunner.py -a
pyrefly check

step 1: uncomment lines in the pyrefly.toml file
step 2: run pyrefly check
step 3: add suppressions, clean up unused suppressions
before: https://gist.github.com/maggiemoss/356645cf8cfe33123d9a27f23b30f7b1

after:

0 errors (2,753 ignored)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164615
Approved by: https://github.com/oulgen
2025-10-06 16:14:36 +00:00

48 lines
1.7 KiB
Python

from typing import Optional
def exportdb_error_message(case_name: str) -> str:
from .examples import all_examples
from torch._utils_internal import log_export_usage
ALL_EXAMPLES = all_examples()
# Detect whether case_name is really registered in exportdb.
if case_name in ALL_EXAMPLES:
url_case_name = case_name.replace("_", "-")
return f"See {case_name} in exportdb for unsupported case. \
https://pytorch.org/docs/main/generated/exportdb/index.html#{url_case_name}"
else:
log_export_usage(
event="export.error.casenotregistered",
message=case_name,
)
return f"{case_name} is unsupported."
def get_class_if_classified_error(e: Exception) -> Optional[str]:
"""
Returns a string case name if the export error e is classified.
Returns None otherwise.
"""
from torch._dynamo.exc import TorchRuntimeError, Unsupported, UserError
ALWAYS_CLASSIFIED = "always_classified"
DEFAULT_CLASS_SIGIL = "case_name"
# add error types that should be classified, along with any attribute name
# whose presence acts like a sigil to further distinguish which errors of
# that type should be classified. If the attribute name is None, then the
# error type is always classified.
_ALLOW_LIST = {
Unsupported: DEFAULT_CLASS_SIGIL,
UserError: DEFAULT_CLASS_SIGIL,
TorchRuntimeError: None,
}
if type(e) in _ALLOW_LIST:
# pyrefly: ignore # index-error
attr_name = _ALLOW_LIST[type(e)]
if attr_name is None:
return ALWAYS_CLASSIFIED
return getattr(e, attr_name, None)
return None