Repository navigation
[dynamo] Restore __dict__, __doc__, __annotations__ and __type_params__ on a rebuilt function - #196475
[dynamo] Restore __dict__, __doc__, __annotations__ and __type_params__ on a rebuilt function#196475bobrenjc93 wants to merge 2 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196475
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 25 PendingAs of commit 6a8eb57 with merge base e67c870 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
[ghstack-poisoned]
|
Claude finished @bobrenjc93's task in 14m 23s —— View job This restores Full reviewPR Review: #196475SummaryCarries Backward Compatibility
Code Quality
Testing
RecommendationRequest Changes
|
|
Folded into #196476: restoring a rebuilt function's attributes and pruning what no guard reads now land in one commit, since either alone regresses its parent (verbatim restore fails the dump for every generic function and for a local function with an unpicklable attribute; pruning needs the restore plumbing). |
Stack from ghstack (oldest at bottom):
types.FunctionType(code, ...)takes__doc__and__annotations__from thecode object and starts with an empty
__dict__.functools.wrapsoverwroteall three on the live function (it copies
__doc__,__annotations__andupdates
__dict__), and a guard rooted at a wrapper reads them: anEQUALS_MATCH on
func.scale_flagorfunc.__doc__, an ID_MATCH on anannotation value. Rebuilt from the code object alone those read None or empty,
the guard rebakes against that at load, and it fails forever with no load
error (or the load raises, for an attribute that is gone).
Carry
__dict__,__doc__,__annotations__and__type_params__in thepickle state next to the defaults. State is applied after memoization, so
wrapper.me = wrapper-- a function reaching itself through its own__dict__-- terminates.__dict__is assigned before__type_params__because on Python < 3.12 the latter has no slot and would land in
__dict__,where a wholesale assignment afterwards would discard it. Annotations are read
with
_read_raw_annotations, which on 3.14+ takes the FORWARDREF format so aTYPE_CHECKING-only name does not raise during the dump; its
resolve=Truemode is for the AOT pickler, which needs real values to serialize.
Test Plan:
All six tests fail or error on the previous commit.
Authored with an AI assistant.