Skip to content

Commit 5965f12

Browse files
asottile-sentryandrewshie-sentry
authored andcommitted
ref: work around type unsafety in analytics Event.from_instance (#96082)
mypy 1.17 notices this illegally passes `None` to several params <!-- Describe your PR here. -->
1 parent 660df21 commit 5965f12

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/sentry/analytics/event.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,18 @@ def from_instance(cls, instance: Any, **kwargs: Any) -> Self:
109109
self.data = get_data(cls.attributes, items)
110110
return self
111111

112-
return cls(
113-
**{
114-
f.name: kwargs.get(f.name, getattr(instance, f.name, None))
115-
for f in fields(cls)
116-
if f.name
117-
not in (
118-
"type",
119-
"uuid_",
120-
"datetime_",
121-
"data", # TODO: remove this data field once migrated
122-
)
123-
}
124-
)
112+
attrs: dict[str, Any] = {
113+
f.name: kwargs.get(f.name, getattr(instance, f.name, None))
114+
for f in fields(cls)
115+
if f.name
116+
not in (
117+
"type",
118+
"uuid_",
119+
"datetime_",
120+
"data", # TODO: remove this data field once migrated
121+
)
122+
}
123+
return cls(**attrs)
125124

126125

127126
def serialize_event(event: Event) -> dict[str, Any]:

0 commit comments

Comments
 (0)