Pyrefly suppressions 7/n (#164913)

Adds suppressions to pyrefly will typecheck clean: https://github.com/pytorch/pytorch/issues/163283

Almost there!

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

step 1: delete lines in the pyrefly.toml file from the project-excludes field
step 2: run pyrefly check
step 3: add suppressions, clean up unused suppressions
before: https://gist.github.com/maggiemoss/4b3bf2037014e116bc00706a16aef199

after:
 INFO 0 errors (6,884 ignored)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164913
Approved by: https://github.com/oulgen
This commit is contained in:
Maggie Moss
2025-10-08 07:27:14 +00:00
committed by PyTorch MergeBot
parent 12d2ef557f
commit c855f8632e
89 changed files with 626 additions and 67 deletions

View File

@ -1028,6 +1028,7 @@ class BuiltinVariable(VariableTracker):
def call_self_handler(tx: "InstructionTranslator", args, kwargs):
try:
# pyrefly: ignore # not-callable
result = self_handler(tx, *args, **kwargs)
if result is not None:
return result
@ -1035,6 +1036,7 @@ class BuiltinVariable(VariableTracker):
# Check if binding is bad. inspect signature bind is expensive.
# So check only when handler call fails.
try:
# pyrefly: ignore # bad-argument-type
inspect.signature(self_handler).bind(tx, *args, **kwargs)
except TypeError as e:
has_constant_handler = obj.has_constant_handler(args, kwargs)
@ -1087,6 +1089,7 @@ class BuiltinVariable(VariableTracker):
hints=[*graph_break_hints.DYNAMO_BUG],
from_exc=exc,
)
# pyrefly: ignore # unbound-name
return VariableTracker.build(tx, res)
else:
@ -1115,6 +1118,7 @@ class BuiltinVariable(VariableTracker):
tx,
args=list(map(ConstantVariable.create, exc.args)),
)
# pyrefly: ignore # unbound-name
return VariableTracker.build(tx, res)
handlers.append(constant_fold_handler)
@ -1437,6 +1441,7 @@ class BuiltinVariable(VariableTracker):
resolved_fn = getattr(self.fn, name)
if resolved_fn in dict_methods:
if isinstance(args[0], variables.UserDefinedDictVariable):
# pyrefly: ignore # missing-attribute
return args[0]._dict_vt.call_method(tx, name, args[1:], kwargs)
elif isinstance(args[0], variables.ConstDictVariable):
return args[0].call_method(tx, name, args[1:], kwargs)
@ -1445,6 +1450,7 @@ class BuiltinVariable(VariableTracker):
resolved_fn = getattr(self.fn, name)
if resolved_fn in set_methods:
if isinstance(args[0], variables.UserDefinedSetVariable):
# pyrefly: ignore # missing-attribute
return args[0]._set_vt.call_method(tx, name, args[1:], kwargs)
elif isinstance(args[0], variables.SetVariable):
return args[0].call_method(tx, name, args[1:], kwargs)
@ -1533,10 +1539,12 @@ class BuiltinVariable(VariableTracker):
if type(arg.value).__str__ is object.__str__:
# Rely on the object str method
try:
# pyrefly: ignore # unbound-name
return variables.ConstantVariable.create(value=str_method())
except AttributeError:
# Graph break
return
# pyrefly: ignore # unbound-name
elif is_wrapper_or_member_descriptor(str_method):
unimplemented_v2(
gb_type="Attempted to a str() method implemented in C/C++",
@ -1653,8 +1661,10 @@ class BuiltinVariable(VariableTracker):
else:
raw_b = b.raw_value
if self.fn is max:
# pyrefly: ignore # missing-attribute
raw_res = max(a.raw_value, raw_b)
else:
# pyrefly: ignore # missing-attribute
raw_res = min(a.raw_value, raw_b)
need_unwrap = any(
@ -2106,6 +2116,7 @@ class BuiltinVariable(VariableTracker):
)
if isinstance(arg, variables.UserDefinedExceptionClassVariable):
# pyrefly: ignore # unbound-name
return ConstantVariable.create(isinstance(arg_type, isinstance_type))
isinstance_type_tuple: tuple[type, ...]
@ -2138,8 +2149,10 @@ class BuiltinVariable(VariableTracker):
# through it. This is a limitation of the current implementation.
# Usually `__subclasscheck__` and `__instancecheck__` can be constant fold through, it
# might not be a big issue and we trade off it for performance.
# pyrefly: ignore # unbound-name
val = issubclass(arg_type, isinstance_type_tuple)
except TypeError:
# pyrefly: ignore # unbound-name
val = arg_type in isinstance_type_tuple
return variables.ConstantVariable.create(val)
@ -2161,6 +2174,7 @@ class BuiltinVariable(VariableTracker):
# WARNING: This might run arbitrary user code `__subclasscheck__`.
# See the comment in call_isinstance above.
# pyrefly: ignore # unbound-name
return variables.ConstantVariable(issubclass(left_ty_py, right_ty_py))
def call_super(self, tx: "InstructionTranslator", a, b):
@ -2206,7 +2220,9 @@ class BuiltinVariable(VariableTracker):
value = getattr(self.fn, name)
except AttributeError:
raise_observed_exception(AttributeError, tx)
# pyrefly: ignore # unbound-name
if not callable(value):
# pyrefly: ignore # unbound-name
return VariableTracker.build(tx, value, source)
return variables.GetAttrVariable(self, name, source=source)