From 7ba2f4cb781dc618ac7067babdf8df890e451e89 Mon Sep 17 00:00:00 2001 From: Sandy Spicer Date: Thu, 19 Dec 2024 14:16:53 -0800 Subject: [PATCH] mypy --- posthog/hogql/query.py | 12 +++++------- posthog/models/cohort/util.py | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/posthog/hogql/query.py b/posthog/hogql/query.py index 8b75131675f57..8d0083e440e13 100644 --- a/posthog/hogql/query.py +++ b/posthog/hogql/query.py @@ -1,5 +1,5 @@ import dataclasses -from typing import Optional, Union, cast +from typing import Optional, Union, cast, ClassVar from posthog.clickhouse.client.connection import Workload from posthog.errors import ExposedCHQueryError @@ -48,15 +48,13 @@ class HogQLQueryExecutor: settings: Optional[HogQLGlobalSettings] = None modifiers: Optional[HogQLQueryModifiers] = None limit_context: Optional[LimitContext] = LimitContext.QUERY - timings: Optional[HogQLTimings] = None + timings: HogQLTimings = dataclasses.field(default_factory=HogQLTimings) pretty: Optional[bool] = True - context: Optional[HogQLContext] = None + __uninitialized_context: ClassVar[HogQLContext] = HogQLContext() + context: HogQLContext = dataclasses.field(default_factory=lambda: HogQLQueryExecutor.__uninitialized_context) def __post_init__(self): - if self.timings is None: - self.timings = HogQLTimings() - - if self.context is None: + if self.context is self.__uninitialized_context: self.context = HogQLContext(team_id=self.team.pk) self.query_modifiers = create_default_modifiers_for_team(self.team, self.modifiers) diff --git a/posthog/models/cohort/util.py b/posthog/models/cohort/util.py index 01e13026ec45b..34f7cb49a6492 100644 --- a/posthog/models/cohort/util.py +++ b/posthog/models/cohort/util.py @@ -375,10 +375,10 @@ def _recalculate_cohortpeople_for_team( def _recalculate_cohortpeople_for_team_hogql( cohort: Cohort, pending_version: int, team: Team, *, initiating_user_id: Optional[int] -) -> Optional[int]: +): # No need to do anything here, as we're only testing hogql if cohort.is_static or not cohort.properties.values: - return None + return from posthog.hogql_queries.hogql_cohort_query import HogQLCohortQuery from posthog.hogql.query import HogQLQueryExecutor