Skip to content

Force keyword-only args for Duration (prevent footgun)#19756

Merged
MadLittleMods merged 3 commits into
developfrom
madlittlemods/duration-init-footgun
May 7, 2026
Merged

Force keyword-only args for Duration (prevent footgun)#19756
MadLittleMods merged 3 commits into
developfrom
madlittlemods/duration-init-footgun

Conversation

@MadLittleMods

@MadLittleMods MadLittleMods commented May 5, 2026

Copy link
Copy Markdown
Contributor

Force keyword-only args for Duration (prevent footgun) so people have to specify which time unit they want to use.

Spawning from #19394 (comment)

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

Comment thread synapse/util/duration.py
hours=hours,
weeks=weeks,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you forget the keyword arg now, the linter complains like this:

Duration(5)

synapse/handlers/worker_lock.py:264: error: Too many positional arguments for "Duration"  [misc]

@MadLittleMods MadLittleMods marked this pull request as ready for review May 5, 2026 19:19
@MadLittleMods MadLittleMods requested a review from a team as a code owner May 5, 2026 19:19
@MadLittleMods MadLittleMods merged commit 4911296 into develop May 7, 2026
46 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/duration-init-footgun branch May 7, 2026 15:38
@MadLittleMods

Copy link
Copy Markdown
Contributor Author

Thanks for the review @erikjohnston 🦐

FrenchGithubUser pushed a commit to famedly/synapse-upstreaming that referenced this pull request Jun 12, 2026
…19756)

So people have to specify which time unit they want to use.

Spawning from
element-hq#19394 (comment)
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.

2 participants