Type opaque-input predicate/lookup surfaces as object (#190599)
Summary:
The classify-an-arbitrary-object surface in trace_rules.py and utils.py
took bare `Any` for the inbound object even though every one of these
functions either hashes it, compares its `id()`, or immediately branches
on `isinstance`/`istype`. `Any` disables checking at every call site and
lets genuinely wrong arguments through silently, so widen the inbound
parameter to `object`, which still accepts anything but forces callers
and bodies to narrow before use.
trace_rules.py: the `is_*` predicates (is_callable_allowed/disallowed,
is_leaf_function, is_nonstrict_trace_callable, is_forbidden,
is_builtin_callable/constant, is_polyfilled_callable, is_numpy/_dtype/
_type_info, is_aten_op_or_tensor_method) plus the lookup surface
(check_verbose/check/get_skip_reason/lookup/lookup_inner/_lookup_inner).
The `frame` parameters on check/check_verbose are intentionally left as
`Any | None` since they are a separate concern (they want
types.FrameType | None) and are dereferenced directly.
utils.py: hashable, is_typing, is_numpy_int/float_type, getfile,
is_namedtuple/_cls, is_safe_constant, is_torch_sym, object_has_getattribute,
is_safe_numpy_wrapper, is_utils_checkpoint, is_invoke_subgraph,
is_rng_state_getter_or_setter, is_tensor_base_attr_getter,
is_torch_function_object, is_frozen_dataclass, is_pybind11_enum_member,
is_lru_cache_wrapper_trace_without_warning_allowed.
Two callees are typed more narrowly than `object`: is_namedtuple_cls gains
an explicit `isinstance(cls, type)` guard (equivalent to the pre-existing
issubclass TypeError catch, and it now narrows for `.__bases__`/`.__new__`),
and getfile/is_frozen_dataclass carry a localized `type: ignore` at the
inspect.getfile / class_has_getattribute boundary where the stub is
narrower than the runtime contract. does_not_override_dict_iter_methods is
deliberately left as `Any` because it dereferences `.items`/`.values`/etc.
on the class without an isinstance guard, so `object` would require several
suppressions.
X-link: https://github.com/pytorch/pytorch/pull/190599
Approved by: https://github.com/jansel
Reviewed By: izaitsevfb
Differential Revision: D114802727
fbshipit-source-id: 71b59f4e7a13e8336ce693f30b6687ca481bd06e