fix(twitter): remove redundant inner 'import os' causing UnboundLocalError on configure#185
Closed
Panniantong wants to merge 1 commit intomainfrom
Closed
fix(twitter): remove redundant inner 'import os' causing UnboundLocalError on configure#185Panniantong wants to merge 1 commit intomainfrom
Panniantong wants to merge 1 commit intomainfrom
Conversation
…Error The twitter-cookies configure handler had 'import os' inside an inner try/except block (line 954). Python's scoping rules treat any binding of a name in a function scope as local for the *entire* function — so the top-level 'import os' at line 15 was shadowed, making every 'os.xxx' call before the inner import raise: UnboundLocalError: cannot access local variable 'os' where it is not associated with a value Fix: remove the redundant inner 'import os'; 'os' is already imported at module level and is accessible throughout cli.py. Fixes #183
Owner
Author
|
Closing — this fix is no longer needed after PR #196 refactored the cookie parsing logic into a standalone helper function. The redundant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #183
agent-reach configure twitter-cookies "auth_token=...; ct0=..."prints:Root Cause
Inside
_cmd_configure(), thetwitter-cookiesbranch has a nestedimport os(line 954, inside a try block for the xreach test step):Python's scoping rules treat any name binding (including
import) as local to the entire function. So the module-levelimport osat line 15 was shadowed, making everyos.xxxcall before the inner import (line 927–941:os.path.join,os.makedirs,os.path.exists,os.chmod) raise:Fix
Remove the redundant
import osline —osis already imported at module level.Verification
python3 -c "import agent_reach.cli"→ OKpython3 -m pytest tests/ -x -q→ 49 passed