HwpxDocument에 컨텍스트 매니저 및 안전한 자원 정리 추가#17
Merged
Conversation
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.
Motivation
HwpxDocument를with구문으로 안전하게 사용할 수 있도록 컨텍스트 매니저 진입/종료 동작과 자원 정리 정책을 도입했습니다.HwpxDocument.open(bytes)) 등 내부에서 생성한 스트림을 문서 수명 종료 시 자동으로 정리하도록 처리해야 했습니다.Description
HwpxDocument에__enter__,__exit__,close()메서드를 추가해 컨텍스트 매니저를 지원하고close()는 멱등적으로 동작하도록 구현했습니다.flush()가능한 자원은 먼저flush()를 호출하고 이후close()를 호출하며 정리 중 발생한 예외는 로깅 후 무시하도록 구현했습니다.HwpxDocument.open(...)에서bytes입력 경로는 내부적으로io.BytesIO스트림을 생성하여managed_resources에 등록하도록 변경해 블록 종료 시 자동 정리되도록 했습니다.docs/quickstart.md)에HwpxDocument.open(...)과with사용 예제를 추가하고, 자원 정리 동작을 검증하는 새로운 테스트tests/test_document_context_manager.py를 추가했습니다.Testing
pytest -q tests/test_document_context_manager.py를 실행했고 결과는3 passed, 1 warning으로 테스트가 모두 성공했습니다.Codex Task