Skip to content

Make the optional parameters keyword-only - #45

Open
vringar wants to merge 1 commit into
masterfrom
api/keyword-only
Open

Make the optional parameters keyword-only#45
vringar wants to merge 1 commit into
masterfrom
api/keyword-only

Conversation

@vringar

@vringar vringar commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Make the optional parameters keyword-only

Every parameter but the url is now keyword-only on stem_url,
hostname_subparts, get_scheme and get_port. Five of them are booleans, and
stem_url(url, True, 'http', False, True) says nothing at the call site about
which of scheme, path, parse_ws or return_unparsed is which. OpenWPM, the
consumer this library exists for, only ever calls get_ps_plus_1(url) with a
single positional argument, and the test suite already passes everything by
keyword, so nothing in reach has to change.

It also makes the _StemKwargs duplication checkable. That TypedDict restates
stem_url's keyword parameters so the functions forwarding **kwargs to it stay
type-checked at their call sites; PEP 692 only goes from a TypedDict to
**kwargs, so nothing in the language binds them together, and the pair can
drift silently. With the parameters keyword-only the invariant is exact --
every keyword-only parameter, and no other, appears in the TypedDict -- and a
test now asserts it by reflection.

Every parameter but the url is now keyword-only on stem_url,
hostname_subparts, get_scheme and get_port. Five of them are booleans, and
`stem_url(url, True, 'http', False, True)` says nothing at the call site about
which of scheme, path, parse_ws or return_unparsed is which. OpenWPM, the
consumer this library exists for, only ever calls get_ps_plus_1(url) with a
single positional argument, and the test suite already passes everything by
keyword, so nothing in reach has to change.

It also makes the _StemKwargs duplication checkable. That TypedDict restates
stem_url's keyword parameters so the functions forwarding **kwargs to it stay
type-checked at their call sites; PEP 692 only goes from a TypedDict to
**kwargs, so nothing in the language binds them together, and the pair can
drift silently. With the parameters keyword-only the invariant is exact --
every keyword-only parameter, and no other, appears in the TypedDict -- and a
test now asserts it by reflection.
Base automatically changed from ci/action-versions to master September 1, 2026 14:05
@vringar vringar mentioned this pull request Sep 5, 2026
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