fix: set the lang browser flag from Config instead of add_argument - #272
Open
bercedev wants to merge 1 commit into
Open
fix: set the lang browser flag from Config instead of add_argument#272bercedev wants to merge 1 commit into
bercedev wants to merge 1 commit into
Conversation
Browser.start appended `--lang=<lang>` through Config.add_argument, but add_argument rejects any argument containing "lang" and tells the caller to use a Config attribute instead. Setting that very attribute therefore always raised ValueError, which made the `lang` option unusable through every entry point (zd.start(lang=...), Browser.create(lang=...), Config(lang=...)). Emit the flag from Config.__call__ alongside the other attribute-backed flags (headless, user_agent, sandbox), so the add_argument guard stays intact and lang behaves like every other Config option.
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.
Closes #262.
The problem
Browser.startappends the flag throughConfig.add_argument:but
add_argumentrejects any argument containing"lang":So setting the attribute the error message points to is exactly what triggers the error.
langis unusable through every entry point:Same for
Browser.create(lang=...)andConfig(lang=...). The only way to get the flag through today is to bypass the attribute entirely —Config(browser_args=["--lang=en-US"])works, because arguments passed to the constructor are not validated.The fix
Emit the flag from
Config.__call__, next to the other attribute-backed flags:and drop the
add_argumentcall fromBrowser.start. This matches howheadless,user_agentandsandboxare already handled, keeps theadd_argumentguard intact, and needs no new API.Tests
tests/core/test_config.py(new): the flag is emitted whenlangis set, omitted when it is not, composes withbrowser_args, andadd_argument("--lang=…")still raises.tests/core/test_browser.py: a browser actually starts withlangset — this is the regression that produced theValueError.tests/conftest.py:CreateBrowseracceptslangso the test above can pass it.Verified with
scripts/lint.sh(ruff + mypy clean) and the tests above on Chromium 151.Note
Worth flagging separately:
--langdoes not changenavigator.language, which keeps reporting the browser's installed UI language. That is Chromium behaviour rather than something this PR changes, so I left it alone — happy to open a separate issue if you would like it documented.