This repository was archived by the owner on Nov 26, 2026. It is now read-only.
Repository navigation
fix(utils): return None from flatten_errors when there is no error - #26
Open
PttCodingMan wants to merge 1 commit into
Open
PttCodingMan wants to merge 1 commit into
PttCodingMan wants to merge 1 commit into
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
這個 PR 的目的 / Purpose of this PR
utils.util.flatten_errors()用filter(...)過濾出有錯誤的項目後,直接用if not the_errors判斷是否沒有錯誤。在 Python 3 中filter回傳的是 iterator,永遠為 truthy,所以return None, the_list這個分支永遠不會執行;沒有錯誤時實際回傳的是空字串''而不是None。目前呼叫端剛好用if err:判斷所以沒出事,但函式的回傳值與預期(None表示沒有錯誤)不符。本 PR 將filter結果轉成list。flatten_errors()filters the failed items withfilter(...)and then checksif not the_errors. In Python 3filterreturns an iterator, which is always truthy, so thereturn None, the_listbranch was unreachable and the function returned''instead ofNonewhen there were no errors. Current callers useif err:so it went unnoticed, but the return value did not match the intended contract. This PR wraps the result inlist(...).驗證 / Verification
環境:Python 3.10 venv,依
setup.py安裝依賴(另外 pinmongoengine==0.20.0、pymongo<4),測試使用 mongomock。nose1.3.7 在 Python 3.10 無法執行,所以改用pytest<8並以暫時的conftest.py(不 commit)呼叫tests.setup()。Environment: Python 3.10 venv with the
setup.pydependencies (plusmongoengine==0.20.0,pymongo<4); tests use mongomock.nose1.3.7 does not run on Python 3.10, so I usedpytest<8with a temporary, uncommittedconftest.pythat callstests.setup().新增
test_flatten_errors_no_error/test_flatten_errors_with_error;修正前前者失敗:AssertionError: '' is not None修正後
python -m pytest -q tests:51 passedAdded
test_flatten_errors_no_error/test_flatten_errors_with_error; before the fix the former fails withAssertionError: '' is not None.After the fix,
python -m pytest -q tests:51 passed.相關的 issue / Related Issues
無 / None