Repository navigation
Remove some call_obj_hasattr in favor of a centralized hasattr - #197322
guilhermeleobas wants to merge 12 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197322
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 72a2241 with merge base d5e5e58 ( 🟡 GREEN LIGHT - PR was reverted - re-landing requires human review:
Green Light will not review this PR again, on this or any later commit; re-landing it needs a human approval. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
[ghstack-poisoned]
| # pre-existing builtin.py check: a non-constant str name wrongly raises | ||
| # TypeError instead of graph breaking. | ||
| if not name.is_python_constant(): | ||
| raise_observed_exception(TypeError, tx) |
There was a problem hiding this comment.
Why not just graph break here?
There was a problem hiding this comment.
This comment is a bit misleading as raising a TypeError here is the correct behavior. See:
https://github.com/python/cpython/blob/848cb25624ab44c9fef2966c777419376b65af1b/Objects/object.c#L1404-L1409
| if tx.output.side_effects.has_pending_mutation_of_attr(obj, name): | ||
| value = tx.output.side_effects.load_attr(obj, name, deleted_ok=True) | ||
| return not isinstance(value, variables.DeletedVariable) | ||
|
|
There was a problem hiding this comment.
I think we can install the guard here. Right now we're missing a guard if the attribute exists, i.e this gives the wrong answer
import torch
@torch.compile(backend="eager", fullgraph=True)
def f(x, o):
if hasattr(o, "a"):
return x + 1
return x - 1
class obj:
pass
o = obj()
o.a = "a"
print(f(torch.zeros(3, 3), o))
del o.a
print(f(torch.zeros(3, 3), o))
[ghstack-poisoned]
| if tx.output.side_effects.has_pending_mutation_of_attr(obj, name): | ||
| value = tx.output.side_effects.load_attr(obj, name, deleted_ok=True) | ||
| return not isinstance(value, variables.DeletedVariable) |
There was a problem hiding this comment.
I don't think this shortcut is valid in general - it can skip tracing custom getattr, or fail for class attrs that are shadowed by deleted instance attrs. Can we get rid of it and do it in each VT's tp_getattro_impl
functions instead?
class K:
a = "class"
@torch.compile(backend="eager", fullgraph=True)
def f(x, o):
o.a = 1
del o.a
return x + 1 if hasattr(o, "a") else x - 1 # eager: x + 1, compiled: x - 1
f(torch.zeros(1), K())
| except (NotImplementedError, Unsupported): | ||
| pass | ||
|
|
||
| # tp_getattro_impl could not resolve the name. generic_getattr would defer | ||
| # by wrapping it in a GetAttrVariable, which is indistinguishable from a | ||
| # missing attribute, so ask the concrete object (or its type) instead. | ||
| probe = NO_SUCH_SUBOBJ | ||
| for get_probe in (obj.get_real_python_backed_value, obj.python_type): | ||
| try: | ||
| probe = get_probe() | ||
| except (NotImplementedError, AttributeError): | ||
| continue | ||
| if probe is not NO_SUCH_SUBOBJ: | ||
| break | ||
| if probe is not NO_SUCH_SUBOBJ: | ||
| found = hasattr(probe, name) | ||
| if not found and obj.source: | ||
| install_guard( | ||
| obj.source.make_guard( | ||
| functools.partial(GuardBuilder.HASATTR, attr=name) | ||
| ) | ||
| ) | ||
| return found |
There was a problem hiding this comment.
My agent found some regressions here
Following up on my earlier guard comment: the main path is fixed now, but this fallback has a few problems:
- A True answer from the probe doesn't install a guard, so the result goes stale.
- Catching
Unsupportedhere hides graph breaks. The realhasattrthen runs the user's getter once, at compile time, even withfullgraph=True.- When there's no real object, it asks
python_type(), which answers for the type, not the instance.import torch # 1. True from the fallback installs no guard class Fn(torch.autograd.Function): @staticmethod def forward(ctx, x): return x @staticmethod def backward(ctx, g): return g Fn.flag = 1 @torch.compile(backend="eager", fullgraph=True) def f(x): return x + 1 if hasattr(Fn, "flag") else x - 1 print(f(torch.zeros(1))) # tensor([1.]) del Fn.flag print(f(torch.zeros(1))) # eager: tensor([-1.]), compiled: tensor([1.]) # 2. Unsupported is swallowed and the getter runs at compile time log = [] class A: @property def p(self): torch._dynamo.graph_break() log.append("p") return 1 @torch.compile(backend="eager", fullgraph=True) def g(x, a): return x + 1 if hasattr(a, "p") else x - 1 for _ in range(3): log.clear() g(torch.zeros(1), A()) print(log) # eager: ['p'] every call; compiled: no error under fullgraph, ['p'] then [] [] # 3. With no real object, the answer comes from the type @torch.compile(backend="eager", fullgraph=True) def h(x): return x + 1 if hasattr(iter(range(3)), "__name__") else x - 1 print(h(torch.zeros(1))) # eager: tensor([-1.]), compiled: tensor([1.])All three gave the eager answer before this PR. For (2) that means the
Unsupportedgraph break under fullgraph.Can we guard both answers on this path, and graph break instead of probing when
tp_getattro_implraisesUnsupportedor there's no real object?
There was a problem hiding this comment.
Moving PR to draft. There are some corner cases that are not easy to fix
[ghstack-poisoned]
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: e085aa0 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 3333b2a Pull-Request: pytorch#203908
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: ac8cd3e Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 339cd58 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 8676bbf Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 10bd401 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 688749a Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 6343351 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 1497fd5 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 96ed633 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: e2f307e Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 9715a87 Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 15653ad Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 2b9720f Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 5f634dc Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 57d66ec Pull-Request: pytorch#203908
Resolve defaulted getattr through the existing descriptor path once, instead of probing and then reading a user getter twice. Guard instance/class absence and the MRO lookup hook, including inherited __getattribute__, so adding a lookup hook cannot leave a previously compiled default in the graph. Keep pending instance/class writes visible without invoking getters again. Immutable builtin iterables can report missing attributes directly when their actual runtime type has generic lookup. Preserve AttributeError metadata and set-family iterator types. Retain the locally required behavior while optional-attribute work in pytorch#197322 lands separately; mapping construction and update consumers remain in the following PR. At the native-matched Python3.15 CPU prefix,25 dictionary attribute cases and21 getattr function cases pass. The existing added-lookup-hook regression fails for direct and inherited __getattribute__ when only the MRO-hook protection is removed. The iterator selection runs25 cases with two existing expected failures. Pinned lint and explicit hidden-worktree typing pass. Older-Python and free-threaded execution remains pending. ```bash python3 test/dynamo/test_functions.py -k getattr python3 test/dynamo/test_dicts.py -k attribute -k getattr -k absence python3 test/dynamo/test_iterators.py -k missing -k attribute ``` Prepared with an AI assistant for local human review. ghstack-source-id: 3504eab Pull-Request: pytorch#203908
Stack from ghstack (oldest at bottom):
call_obj_hasattrin favor of a centralizedhasattr#197322cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98