Skip to content

Fix import guard to allow library usage#4

Open
hyeeyoungkim wants to merge 1 commit intodecirella:mainfrom
hyeeyoungkim:pr/fix-import-guard
Open

Fix import guard to allow library usage#4
hyeeyoungkim wants to merge 1 commit intodecirella:mainfrom
hyeeyoungkim:pr/fix-import-guard

Conversation

@hyeeyoungkim
Copy link
Copy Markdown

Summary

  • Wrap args = parser.parse_args() and main(args) (lines 1693-1694) in an
    if __name__ == "__main__": guard so that import yesc no longer triggers
    argument parsing and execution

Problem

The debug lines at the end of yesc.py sit at module level (outside the
if __name__ guard), which means any import yesc immediately calls
parser.parse_args() and main(args). This prevents using yesc as a library
— for example, building args programmatically and calling main(args) from
another script.

The commented-out try/except block (lines 1682-1691) was the original
implementation inside the guard. The current lines were placed at module level
for debugging and left in place.

Change

Add if __name__ == "__main__": guard around lines 1693-1694 and indent them.
The ''' string literal on line 1691 exits the original if __name__ block
(it's at column 0), so these lines need their own guard rather than indenting
into the existing one.

Impact

  • CLI usage (python yesc.py ...): No change — __name__ is "__main__",
    guard fires as before
  • PyInstaller executable (yesc.exe): No change — same reason
  • Library import (from yesc import main): Now works without side effects

- Wrap parse_args() and main() in if __name__ guard
- Add import guard tests (tests/test_import_guard.py)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant