-
Notifications
You must be signed in to change notification settings - Fork 507
chore(contrib): ensure core.dispatch is called with tuples #17960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 3 commits into
main
from
brettlangdon/dispatch.contrib.typing
May 11, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| id: core-dispatch-list-args-bare-multi | ||
| message: Pass a tuple, not a list, to `dispatch()` | ||
| severity: error | ||
| language: python | ||
| fix: dispatch($EVENT, ($FIRST, $$$REST)) | ||
| rule: | ||
| pattern: dispatch($EVENT, [$FIRST, $$$REST]) | ||
| ignores: | ||
| - "ddtrace/internal/core/__init__.py" | ||
| - "ddtrace/internal/core/event_hub.py" | ||
| note: | | ||
| `dispatch()` (imported from `ddtrace.internal.core`) is typed as | ||
| `args: tuple[Any, ...]`. Passing a list literal violates the type contract. | ||
|
|
||
| Before: | ||
| dispatch("my.event", [arg1, arg2]) | ||
|
|
||
| After: | ||
| dispatch("my.event", (arg1, arg2)) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| id: core-dispatch-list-args-bare-single | ||
| message: Pass a tuple, not a list, to `dispatch()` — single-element tuples need a trailing comma | ||
| severity: error | ||
| language: python | ||
| fix: dispatch($EVENT, ($ARG,)) | ||
| rule: | ||
| pattern: dispatch($EVENT, [$ARG]) | ||
| ignores: | ||
| - "ddtrace/internal/core/__init__.py" | ||
| - "ddtrace/internal/core/event_hub.py" | ||
| note: | | ||
| `dispatch()` (imported from `ddtrace.internal.core`) is typed as | ||
| `args: tuple[Any, ...]`. Passing a list literal violates the type contract. | ||
| Single-element tuples require a trailing comma. | ||
|
|
||
| Before: | ||
| dispatch("my.event", [arg]) | ||
|
|
||
| After: | ||
| dispatch("my.event", (arg,)) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| id: core-dispatch-list-args-multi | ||
| message: Pass a tuple, not a list, to `core.dispatch()` | ||
| severity: error | ||
| language: python | ||
| fix: $OBJ.dispatch($EVENT, ($FIRST, $$$REST)) | ||
| rule: | ||
| pattern: $OBJ.dispatch($EVENT, [$FIRST, $$$REST]) | ||
| constraints: | ||
| OBJ: | ||
| regex: "^(core|event_hub)$" | ||
| note: | | ||
| `core.dispatch()` is typed as `args: tuple[Any, ...]`. Passing a list literal | ||
| violates the type contract. | ||
|
|
||
| Before: | ||
| core.dispatch("my.event", [arg1, arg2]) | ||
|
|
||
| After: | ||
| core.dispatch("my.event", (arg1, arg2)) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| id: core-dispatch-list-args-single | ||
| message: Pass a tuple, not a list, to `core.dispatch()` — single-element tuples need a trailing comma | ||
| severity: error | ||
| language: python | ||
| fix: $OBJ.dispatch($EVENT, ($ARG,)) | ||
| rule: | ||
| pattern: $OBJ.dispatch($EVENT, [$ARG]) | ||
| constraints: | ||
| OBJ: | ||
| regex: "^(core|event_hub)$" | ||
| note: | | ||
| `core.dispatch()` is typed as `args: tuple[Any, ...]`. Passing a list literal | ||
| violates the type contract. Single-element tuples require a trailing comma. | ||
|
|
||
| Before: | ||
| core.dispatch("my.event", [arg]) | ||
|
|
||
| After: | ||
| core.dispatch("my.event", (arg,)) |
31 changes: 31 additions & 0 deletions
31
.sg/tests/__snapshots__/core-dispatch-list-args-bare-multi-snapshot.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| id: core-dispatch-list-args-bare-multi | ||
| snapshots: | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (ctx, span, result)) | ||
| labels: | ||
| - source: |- | ||
| dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) | ||
| style: primary | ||
| start: 43 | ||
| end: 95 | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg1, arg2]) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg1, arg2)) | ||
| labels: | ||
| - source: dispatch("my.event", [arg1, arg2]) | ||
| style: primary | ||
| start: 43 | ||
| end: 77 |
31 changes: 31 additions & 0 deletions
31
.sg/tests/__snapshots__/core-dispatch-list-args-bare-single-snapshot.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| id: core-dispatch-list-args-bare-single | ||
| snapshots: | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (ctx,)) | ||
| labels: | ||
| - source: |- | ||
| dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) | ||
| style: primary | ||
| start: 43 | ||
| end: 81 | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg]) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg,)) | ||
| labels: | ||
| - source: dispatch("my.event", [arg]) | ||
| style: primary | ||
| start: 43 | ||
| end: 70 |
75 changes: 75 additions & 0 deletions
75
.sg/tests/__snapshots__/core-dispatch-list-args-multi-snapshot.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| id: core-dispatch-list-args-multi | ||
| snapshots: | ||
| ? | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ | ||
| arg1, | ||
| arg2, | ||
| arg3, | ||
| ], | ||
| ) | ||
| : fixed: | | ||
| core.dispatch("my.event", (arg1, arg2, | ||
| arg3,)) | ||
| labels: | ||
| - source: |- | ||
| core.dispatch( | ||
| "my.event", | ||
| [ | ||
| arg1, | ||
| arg2, | ||
| arg3, | ||
| ], | ||
| ) | ||
| style: primary | ||
| start: 0 | ||
| end: 87 | ||
| ? | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) | ||
| : fixed: | | ||
| core.dispatch("my.event", (ctx, span, result)) | ||
| labels: | ||
| - source: |- | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) | ||
| style: primary | ||
| start: 0 | ||
| end: 57 | ||
| core.dispatch("my.event", [arg1, arg2, arg3]): | ||
| fixed: core.dispatch("my.event", (arg1, arg2, arg3)) | ||
| labels: | ||
| - source: core.dispatch("my.event", [arg1, arg2, arg3]) | ||
| style: primary | ||
| start: 0 | ||
| end: 45 | ||
| core.dispatch("my.event", [arg1, arg2]): | ||
| fixed: core.dispatch("my.event", (arg1, arg2)) | ||
| labels: | ||
| - source: core.dispatch("my.event", [arg1, arg2]) | ||
| style: primary | ||
| start: 0 | ||
| end: 39 | ||
| core.dispatch("my.event", [ctx, rowcount]): | ||
| fixed: core.dispatch("my.event", (ctx, rowcount)) | ||
| labels: | ||
| - source: core.dispatch("my.event", [ctx, rowcount]) | ||
| style: primary | ||
| start: 0 | ||
| end: 42 | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg1, arg2]) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| .dispatch("my.event", (arg1, arg2)) | ||
| labels: | ||
| - source: dispatch("my.event", [arg1, arg2]) | ||
| style: primary | ||
| start: 43 | ||
| end: 77 |
43 changes: 43 additions & 0 deletions
43
.sg/tests/__snapshots__/core-dispatch-list-args-single-snapshot.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| id: core-dispatch-list-args-single | ||
| snapshots: | ||
| ? | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) | ||
| : fixed: | | ||
| core.dispatch("my.event", (ctx,)) | ||
| labels: | ||
| - source: |- | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) | ||
| style: primary | ||
| start: 0 | ||
| end: 43 | ||
| core.dispatch("my.event", [arg]): | ||
| fixed: core.dispatch("my.event", (arg,)) | ||
| labels: | ||
| - source: core.dispatch("my.event", [arg]) | ||
| style: primary | ||
| start: 0 | ||
| end: 32 | ||
| core.dispatch("my.event", [ctx]): | ||
| fixed: core.dispatch("my.event", (ctx,)) | ||
| labels: | ||
| - source: core.dispatch("my.event", [ctx]) | ||
| style: primary | ||
| start: 0 | ||
| end: 32 | ||
| ? | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg]) | ||
| : fixed: | | ||
| from ddtrace.internal.core import dispatch | ||
| .dispatch("my.event", (arg,)) | ||
| labels: | ||
| - source: dispatch("my.event", [arg]) | ||
| style: primary | ||
| start: 43 | ||
| end: 70 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| id: core-dispatch-list-args-bare-multi | ||
| valid: | ||
| # Tuple (correct) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg1, arg2)) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg1, arg2, arg3)) | ||
| # Single-element tuple — handled by the -single rule | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg,)) | ||
| # Variable (not a list literal) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", args) | ||
| # Qualified form — handled by the non-bare rules | ||
| - core.dispatch("my.event", [arg1, arg2]) | ||
|
|
||
| invalid: | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg1, arg2]) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| id: core-dispatch-list-args-bare-single | ||
| valid: | ||
| # Tuple (correct) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg,)) | ||
| # Multi-element tuple — handled by the -multi rule | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", (arg1, arg2)) | ||
| # Variable (not a list literal) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", args) | ||
| # Qualified form — handled by the non-bare rules | ||
| - core.dispatch("my.event", [arg]) | ||
|
|
||
| invalid: | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch("my.event", [arg]) | ||
| - | | ||
| from ddtrace.internal.core import dispatch | ||
| dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| id: core-dispatch-list-args-multi | ||
| valid: | ||
| # Tuple (correct) | ||
| - core.dispatch("my.event", (arg1, arg2)) | ||
| - core.dispatch("my.event", (arg1, arg2, arg3)) | ||
| # Single-element tuple — handled by the -single rule | ||
| - core.dispatch("my.event", (arg,)) | ||
| # Variable (not a list literal) | ||
| - core.dispatch("my.event", args) | ||
| # Non-core dispatcher — must not be flagged even with a list literal | ||
| - some_dispatcher.dispatch("my.event", [arg1, arg2]) | ||
| - self.dispatcher.dispatch("my.event", [arg1, arg2]) | ||
|
|
||
| invalid: | ||
| - core.dispatch("my.event", [arg1, arg2]) | ||
| - core.dispatch("my.event", [ctx, rowcount]) | ||
| - core.dispatch("my.event", [arg1, arg2, arg3]) | ||
| - | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx, span, result], | ||
| ) | ||
| - | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ | ||
| arg1, | ||
| arg2, | ||
| arg3, | ||
| ], | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| id: core-dispatch-list-args-single | ||
| valid: | ||
| # Tuple (correct) | ||
| - core.dispatch("my.event", (arg,)) | ||
| # Multi-element tuple — handled by the -multi rule | ||
| - core.dispatch("my.event", (arg1, arg2)) | ||
| # Variable (not a list literal — can't statically check the type) | ||
| - core.dispatch("my.event", args) | ||
| # Non-core dispatcher — must not be flagged even with a list literal | ||
| - some_dispatcher.dispatch("my.event", [arg]) | ||
| - self.dispatcher.dispatch("my.event", [arg]) | ||
|
|
||
| invalid: | ||
| - core.dispatch("my.event", [arg]) | ||
| - core.dispatch("my.event", [ctx]) | ||
| - | | ||
| core.dispatch( | ||
| "my.event", | ||
| [ctx], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.