Skip to content

fix: align positional argument parsing with parameter positions - #667

Open
juanmicl wants to merge 2 commits into
taskiq-python:masterfrom
juanmicl:fix/worker-arg-parse-alignment
Open

fix: align positional argument parsing with parameter positions#667
juanmicl wants to merge 2 commits into
taskiq-python:masterfrom
juanmicl:fix/worker-arg-parse-alignment

Conversation

@juanmicl

Copy link
Copy Markdown

Closes: #666

parse_params mapped positional arguments to annotations using a counter
that only advanced for annotated parameters, so any unannotated
positional parameter shifted every following argument onto the wrong
annotation (values silently coerced by the wrong type, annotated
parameters never validated).

This PR decouples the positional slot index from annotation presence:

  • every POSITIONAL_ONLY / POSITIONAL_OR_KEYWORD parameter advances
    the slot index, annotated or not;
  • parsing only happens when the parameter actually has an annotation;
  • *args annotations now coerce all remaining positional arguments
    (previously only the first element was coerced);
  • keyword-only parameters go straight to the kwargs branch.

Behavior for fully-annotated signatures is unchanged, all existing
test_params_parser.py cases pass as-is.

Validation: full suite passes (pytest -q, 313 tests), black, ruff
and mypy clean (mypy reports the same 2 pre-existing errors in
taskiq/serializers/ as on master).

@s3rius

s3rius commented Aug 30, 2026

Copy link
Copy Markdown
Member

Okay, that seems like it might some the problem. But would you mind adding some tests to validate the fix?

@juanmicl

Copy link
Copy Markdown
Author

Added 9 tests to tests/receiver/test_params_parser.py covering the cases from the issue:

  • unannotated parameters are left untouched (request_id keeps its string value)
  • annotated parameters after an unannotated one are parsed in their own position (int and datetime)
  • the Can't parse argument N warning now points at the right index
  • *args coercion applies to all elements, not just the first
  • keyword-only params and positional params passed as kwargs

Six of them fail on master and pass with the fix. Full suite passes locally (322 tests), ruff/black/mypy clean.

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.

Worker misparses positional arguments when a preceding parameter lacks a type annotation

2 participants