Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .sg/rules/core-dispatch-list-args-bare-multi.yml
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))
20 changes: 20 additions & 0 deletions .sg/rules/core-dispatch-list-args-bare-single.yml
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,))
19 changes: 19 additions & 0 deletions .sg/rules/core-dispatch-list-args-multi.yml
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])
Comment thread
brettlangdon marked this conversation as resolved.
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))
19 changes: 19 additions & 0 deletions .sg/rules/core-dispatch-list-args-single.yml
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,))
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
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
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
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
30 changes: 30 additions & 0 deletions .sg/tests/core-dispatch-list-args-bare-multi-test.yml
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],
)
27 changes: 27 additions & 0 deletions .sg/tests/core-dispatch-list-args-bare-single-test.yml
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],
)
31 changes: 31 additions & 0 deletions .sg/tests/core-dispatch-list-args-multi-test.yml
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,
],
)
20 changes: 20 additions & 0 deletions .sg/tests/core-dispatch-list-args-single-test.yml
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],
)
Loading
Loading