ADR-017: Keyword-Only Parameters for Request MethodsΒΆ
Estado: Accepted Date: 2026-02-11 Deciders: Rodrigo Roldan
ContextΒΆ
Session request methods (post, put, patch, delete) accept multiple optional
parameters: headers, body, timeout, limits. Two API design options:
Positional arguments:
session.post(url, headers, body, timeout, limits)Keyword-only arguments:
session.post(url, *, headers=None, body=None, ...)
Common errors with positional arguments:
# Bug: body accidentally passed as headers
session.post("http://example.com", "my data")
# Bug: argument order confusion
session.post("http://example.com", None, "my data", None, {"max_body_size": 1024})
DecisionΒΆ
All optional parameters after url are keyword-only (enforced via * separator).
class Session:
def get(self, url: str, headers=None, timeout=5, limits=None) -> Response: ...
def post( # pylint: disable=too-many-arguments
self,
url: str,
*,
headers: Optional[Dict[str, str]] = None,
body: Optional[Union[str, bytes]] = None,
timeout: Optional[float] = 5,
limits: Optional[Dict[str, int]] = None,
) -> Response: ...
Rules:
urlis the only positional parameterget()keeps positional args (nobodyparameter, less risk of confusion)Methods with
body(post,put,patch,delete) use keyword-only argspylint: disable=too-many-argumentsis acceptable for these methods
ConsequencesΒΆ
PositiveΒΆ
Clear intent:
session.post(url, body="data")is unambiguousError prevention: Cannot accidentally swap
headersandbodyExtensible: New parameters can be added without breaking existing calls
Readable: Call sites are self-documenting
NegativeΒΆ
Verbosity: Requires explicit keyword names at call sites
Pylint suppression:
too-many-argumentsneeds inline disable
MitigationsΒΆ
Keyword names are short and intuitive (
body=,timeout=)Pylint suppression is scoped to specific methods, not global
Alternatives ConsideredΒΆ
All positional: Rejected. Error-prone for methods with many optional params.
Config object: Rejected. Over-engineering for 4-5 parameters.
Builder pattern: Rejected. Adds complexity without proportional benefit.
ReferencesΒΆ
PEP 3102: Keyword-Only Arguments
Python requests library API design