From 692724051e53355f80232a9b9678f4d6485d44ee Mon Sep 17 00:00:00 2001 From: Tom Owers Date: Wed, 25 Oct 2023 15:51:49 +0100 Subject: [PATCH] Fixed mypi issues or added ignores --- ee/tasks/send_license_usage.py | 12 ++++++------ posthog/api/data_management.py | 4 ++-- posthog/api/event_definition.py | 8 ++++---- posthog/api/person.py | 4 ++-- posthog/api/plugin.py | 8 ++++---- posthog/api/property_definition.py | 8 ++++---- posthog/api/test/openapi_validation.py | 5 ++++- posthog/api/test/test_signup.py | 5 ++++- posthog/models/feature_flag/flag_matching.py | 9 ++++++--- posthog/models/filters/mixins/common.py | 12 ++++++++---- posthog/models/filters/mixins/funnel.py | 4 ++-- posthog/models/filters/mixins/simplify.py | 12 ++++++------ posthog/plugins/utils.py | 2 +- posthog/queries/actor_base_query.py | 4 ++-- posthog/queries/funnels/test/test_funnel.py | 10 ++++++---- posthog/queries/funnels/test/test_funnel_strict.py | 8 ++++---- .../queries/funnels/test/test_funnel_unordered.py | 8 ++++---- posthog/test/base.py | 6 +++++- 18 files changed, 74 insertions(+), 55 deletions(-) diff --git a/ee/tasks/send_license_usage.py b/ee/tasks/send_license_usage.py index 3e5ba9d23f8bb..1360f124f6b85 100644 --- a/ee/tasks/send_license_usage.py +++ b/ee/tasks/send_license_usage.py @@ -61,9 +61,9 @@ def send_license_usage(): "organization_name": user.current_organization.name, # type: ignore }, groups={ - "organization": str(user.current_organization.id), + "organization": str(user.current_organization.id), # type: ignore "instance": SITE_URL, - }, # type: ignore + }, ) response.raise_for_status() return @@ -78,9 +78,9 @@ def send_license_usage(): "organization_name": user.current_organization.name, # type: ignore }, groups={ - "organization": str(user.current_organization.id), + "organization": str(user.current_organization.id), # type: ignore "instance": SITE_URL, - }, # type: ignore + }, ) except Exception as err: try: @@ -93,9 +93,9 @@ def send_license_usage(): "organization_name": user.current_organization.name, # type: ignore }, groups={ - "organization": str(user.current_organization.id), + "organization": str(user.current_organization.id), # type: ignore "instance": SITE_URL, - }, # type: ignore + }, ) raise err except: diff --git a/posthog/api/data_management.py b/posthog/api/data_management.py index fa4effb0ded13..186f2f83021f7 100644 --- a/posthog/api/data_management.py +++ b/posthog/api/data_management.py @@ -17,9 +17,9 @@ def all_activity(self, request: request.Request, **kwargs): activity_page = load_all_activity( scope_list=["EventDefinition", "PropertyDefinition"], - team_id=request.user.team.id, + team_id=request.user.team.id, # type: ignore limit=limit, page=page, - ) # type: ignore + ) return activity_page_response(activity_page, limit, page, request) diff --git a/posthog/api/event_definition.py b/posthog/api/event_definition.py index d033c05c8df86..6616c8beaddab 100644 --- a/posthog/api/event_definition.py +++ b/posthog/api/event_definition.py @@ -143,9 +143,9 @@ def _ordering_params_from_request( def get_object(self): id = self.kwargs["id"] - if EE_AVAILABLE and self.request.user.organization.is_feature_available( + if EE_AVAILABLE and self.request.user.organization.is_feature_available( # type: ignore AvailableFeature.INGESTION_TAXONOMY - ): # type: ignore + ): from ee.models.event_definition import EnterpriseEventDefinition enterprise_event = EnterpriseEventDefinition.objects.filter(id=id).first() @@ -164,9 +164,9 @@ def get_object(self): def get_serializer_class(self) -> Type[serializers.ModelSerializer]: serializer_class = self.serializer_class - if EE_AVAILABLE and self.request.user.organization.is_feature_available( + if EE_AVAILABLE and self.request.user.organization.is_feature_available( # type: ignore AvailableFeature.INGESTION_TAXONOMY - ): # type: ignore + ): from ee.api.ee_event_definition import EnterpriseEventDefinitionSerializer serializer_class = EnterpriseEventDefinitionSerializer # type: ignore diff --git a/posthog/api/person.py b/posthog/api/person.py index 89a6b6bc61b68..f77363af23b5b 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -432,10 +432,10 @@ def values(self, request: request.Request, **kwargs) -> response.Response: # Try loading as json for dicts or arrays flattened.append( { - "name": convert_property_value(json.loads(value)), + "name": convert_property_value(json.loads(value)), # type: ignore "count": count, } - ) # type: ignore + ) except json.decoder.JSONDecodeError: flattened.append({"name": convert_property_value(value), "count": count}) return response.Response(flattened) diff --git a/posthog/api/plugin.py b/posthog/api/plugin.py index 71bd0a11363da..b39c18a67346a 100644 --- a/posthog/api/plugin.py +++ b/posthog/api/plugin.py @@ -459,10 +459,10 @@ def all_activity(self, request: request.Request, **kwargs): activity_page = load_all_activity( scope_list=["Plugin", "PluginConfig"], - team_id=request.user.team.id, + team_id=request.user.team.id, # type: ignore limit=limit, page=page, - ) # type: ignore + ) return activity_page_response(activity_page, limit, page, request) @@ -585,13 +585,13 @@ def create(self, validated_data: Dict, *args: Any, **kwargs: Any) -> PluginConfi _update_plugin_attachments(self.context["request"], plugin_config) return plugin_config - def update( + def update( # type: ignore self, plugin_config: PluginConfig, validated_data: Dict, *args: Any, **kwargs: Any, - ) -> PluginConfig: # type: ignore + ) -> PluginConfig: _fix_formdata_config_json(self.context["request"], validated_data) validated_data.pop("plugin", None) diff --git a/posthog/api/property_definition.py b/posthog/api/property_definition.py index 486b59dffb01e..6da00daecf445 100644 --- a/posthog/api/property_definition.py +++ b/posthog/api/property_definition.py @@ -468,15 +468,15 @@ def get_queryset(self): property_definition_fields = ", ".join( [ - f'posthog_propertydefinition."{f.column}"' + f'posthog_propertydefinition."{f.column}"' # type: ignore for f in PropertyDefinition._meta.get_fields() if hasattr(f, "column") - ] # type: ignore + ] ) - use_enterprise_taxonomy = self.request.user.organization.is_feature_available( + use_enterprise_taxonomy = self.request.user.organization.is_feature_available( # type: ignore AvailableFeature.INGESTION_TAXONOMY - ) # type: ignore + ) order_by_verified = False if use_enterprise_taxonomy: try: diff --git a/posthog/api/test/openapi_validation.py b/posthog/api/test/openapi_validation.py index 0c3bd22d26896..e86bf5198bb53 100644 --- a/posthog/api/test/openapi_validation.py +++ b/posthog/api/test/openapi_validation.py @@ -56,7 +56,10 @@ def validate_response(openapi_spec: Dict[str, Any], response: Any, path_override request_body_content_type = response.request.get("CONTENT_TYPE", "*/*").split(";")[0] request_body_content_encoding = response.request.get("HTTP_CONTENT_ENCODING", None) - request_body_value = cast(bytes, request_fake_payload._FakePayload__content.getvalue()) # type: ignore + request_body_value = cast( + bytes, + request_fake_payload._FakePayload__content.getvalue(), # type: ignore + ) if request_body_content_encoding == "gzip": request_body = gzip.decompress(request_body_value) elif request_body_content_encoding == "lz64": diff --git a/posthog/api/test/test_signup.py b/posthog/api/test/test_signup.py index 737e5607962ef..8ad336872972d 100644 --- a/posthog/api/test/test_signup.py +++ b/posthog/api/test/test_signup.py @@ -876,7 +876,10 @@ def test_api_invite_sign_up(self, mock_capture): # User is now a member of the organization self.assertEqual(user.organization_memberships.count(), 1) - self.assertEqual(user.organization_memberships.first().organization, self.organization) # type: ignore + self.assertEqual( + user.organization_memberships.first().organization, # type: ignore + self.organization, + ) # Defaults are set correctly self.assertEqual(user.organization, self.organization) diff --git a/posthog/models/feature_flag/flag_matching.py b/posthog/models/feature_flag/flag_matching.py index a8b617cdf2bf0..05c5bbccb8f63 100644 --- a/posthog/models/feature_flag/flag_matching.py +++ b/posthog/models/feature_flag/flag_matching.py @@ -696,7 +696,10 @@ def get_all_feature_flags( SELECT key FROM posthog_featureflag WHERE team_id = %(team_id)s AND ensure_experience_continuity = TRUE AND active = TRUE AND deleted = FALSE AND key NOT IN (SELECT feature_flag_key FROM existing_overrides) """ - cursor.execute(query, {"team_id": team_id, "distinct_ids": tuple(distinct_ids)}) # type: ignore + cursor.execute( + query, + {"team_id": team_id, "distinct_ids": tuple(distinct_ids)}, # type: ignore + ) flags_with_no_overrides = [row[0] for row in cursor.fetchall()] should_write_hash_key_override = len(flags_with_no_overrides) > 0 except Exception as e: @@ -825,10 +828,10 @@ def set_feature_flag_hash_key_overrides(team_id: int, distinct_ids: List[str], h query, { "team_id": team_id, - "distinct_ids": tuple(distinct_ids), + "distinct_ids": tuple(distinct_ids), # type: ignore "hash_key_override": hash_key_override, }, - ) # type: ignore + ) return cursor.rowcount > 0 except IntegrityError as e: diff --git a/posthog/models/filters/mixins/common.py b/posthog/models/filters/mixins/common.py index 183e60955cc26..ae50d71f30656 100644 --- a/posthog/models/filters/mixins/common.py +++ b/posthog/models/filters/mixins/common.py @@ -352,8 +352,10 @@ def date_from(self) -> Optional[datetime.datetime]: return None elif isinstance(self._date_from, str): date, delta_mapping = relative_date_parse_with_delta_mapping( - self._date_from, self.team.timezone_info, always_truncate=True - ) # type: ignore + self._date_from, + self.team.timezone_info, # type: ignore + always_truncate=True, + ) self.date_from_delta_mapping = delta_mapping return date else: @@ -384,8 +386,10 @@ def date_to(self) -> datetime.datetime: ) except ValueError: date, delta_mapping = relative_date_parse_with_delta_mapping( - self._date_to, self.team.timezone_info, always_truncate=True - ) # type: ignore + self._date_to, + self.team.timezone_info, # type: ignore + always_truncate=True, + ) self.date_to_delta_mapping = delta_mapping return date else: diff --git a/posthog/models/filters/mixins/funnel.py b/posthog/models/filters/mixins/funnel.py index 80b630e477926..91312a5030478 100644 --- a/posthog/models/filters/mixins/funnel.py +++ b/posthog/models/filters/mixins/funnel.py @@ -265,10 +265,10 @@ class FunnelTrendsPersonsMixin(BaseParamMixin): def entrance_period_start(self) -> Optional[datetime.datetime]: entrance_period_start_raw = self._data.get(ENTRANCE_PERIOD_START) return ( - relative_date_parse(entrance_period_start_raw, self.team.timezone_info) + relative_date_parse(entrance_period_start_raw, self.team.timezone_info) # type: ignore if entrance_period_start_raw else None - ) # type: ignore + ) @cached_property def drop_off(self) -> Optional[bool]: diff --git a/posthog/models/filters/mixins/simplify.py b/posthog/models/filters/mixins/simplify.py index 17c532900ffcd..4735a95e6a7d6 100644 --- a/posthog/models/filters/mixins/simplify.py +++ b/posthog/models/filters/mixins/simplify.py @@ -39,22 +39,22 @@ def simplify(self: T, team: "Team", **kwargs) -> T: if hasattr(result, "entities_to_dict"): for entity_type, entities in result.entities_to_dict().items(): updated_entities[entity_type] = [ - self._simplify_entity(team, entity_type, entity, **kwargs) for entity in entities - ] # type: ignore + self._simplify_entity(team, entity_type, entity, **kwargs) for entity in entities # type: ignore + ] from posthog.models.property.util import clear_excess_levels prop_group = clear_excess_levels( - self._simplify_property_group(team, result.property_groups, **kwargs), + self._simplify_property_group(team, result.property_groups, **kwargs), # type: ignore skip=True, - ) # type: ignore + ) prop_group = prop_group.to_dict() # type: ignore new_group_props = [] if getattr(result, "aggregation_group_type_index", None) is not None: new_group_props.append( - self._group_set_property(cast(int, result.aggregation_group_type_index)).to_dict() - ) # type: ignore + self._group_set_property(cast(int, result.aggregation_group_type_index)).to_dict() # type: ignore + ) if new_group_props: new_group = {"type": "AND", "values": new_group_props} diff --git a/posthog/plugins/utils.py b/posthog/plugins/utils.py index 2610d8b2eb17d..45eeb5ca94843 100644 --- a/posthog/plugins/utils.py +++ b/posthog/plugins/utils.py @@ -276,7 +276,7 @@ def get_file_from_zip_archive(archive: bytes, filename: str, *, json_parse: bool return json.loads(file_bytes) if isinstance(file_bytes, bytes): return file_bytes.decode("utf-8") - return str(file_bytes) + return str(file_bytes) # type: ignore def get_file_from_tgz_archive(archive: bytes, filename, *, json_parse: bool) -> Any: diff --git a/posthog/queries/actor_base_query.py b/posthog/queries/actor_base_query.py index d9c5818f4cda8..396c216f9c01d 100644 --- a/posthog/queries/actor_base_query.py +++ b/posthog/queries/actor_base_query.py @@ -111,9 +111,9 @@ def get_actors( if ( hasattr(self._filter, "include_recordings") - and self._filter.include_recordings + and self._filter.include_recordings # type: ignore and self._filter.insight in [INSIGHT_PATHS, INSIGHT_TRENDS, INSIGHT_FUNNELS] - ): # type: ignore + ): serialized_actors = self.add_matched_recordings_to_serialized_actors(serialized_actors, raw_result) return actors, serialized_actors, len(raw_result) diff --git a/posthog/queries/funnels/test/test_funnel.py b/posthog/queries/funnels/test/test_funnel.py index f6455def3c58d..334f0dc9c41c0 100644 --- a/posthog/queries/funnels/test/test_funnel.py +++ b/posthog/queries/funnels/test/test_funnel.py @@ -43,22 +43,24 @@ def _create_action(**kwargs): class TestFunnelBreakdown( ClickhouseTestMixin, - funnel_breakdown_test_factory( + funnel_breakdown_test_factory( # type: ignore ClickhouseFunnel, ClickhouseFunnelActors, _create_event, _create_action, _create_person, ), -): # type: ignore +): maxDiff = None pass class TestFunnelConversionTime( ClickhouseTestMixin, - funnel_conversion_time_test_factory(ClickhouseFunnel, ClickhouseFunnelActors, _create_event, _create_person), -): # type: ignore + funnel_conversion_time_test_factory( # type: ignore + ClickhouseFunnel, ClickhouseFunnelActors, _create_event, _create_person + ), +): maxDiff = None pass diff --git a/posthog/queries/funnels/test/test_funnel_strict.py b/posthog/queries/funnels/test/test_funnel_strict.py index e4d2879d91486..0f0d4b691ce21 100644 --- a/posthog/queries/funnels/test/test_funnel_strict.py +++ b/posthog/queries/funnels/test/test_funnel_strict.py @@ -36,14 +36,14 @@ def _create_action(**kwargs): class TestFunnelStrictStepsBreakdown( ClickhouseTestMixin, - funnel_breakdown_test_factory( + funnel_breakdown_test_factory( # type: ignore ClickhouseFunnelStrict, ClickhouseFunnelStrictActors, _create_event, _create_action, _create_person, ), -): # type: ignore +): maxDiff = None def test_basic_funnel_default_funnel_days_breakdown_event(self): @@ -177,13 +177,13 @@ def test_strict_breakdown_events_with_multiple_properties(self): class TestFunnelStrictStepsConversionTime( ClickhouseTestMixin, - funnel_conversion_time_test_factory( + funnel_conversion_time_test_factory( # type: ignore ClickhouseFunnelStrict, ClickhouseFunnelStrictActors, _create_event, _create_person, ), -): # type: ignore +): maxDiff = None pass diff --git a/posthog/queries/funnels/test/test_funnel_unordered.py b/posthog/queries/funnels/test/test_funnel_unordered.py index ed30dca41d97f..ce3643d007fc6 100644 --- a/posthog/queries/funnels/test/test_funnel_unordered.py +++ b/posthog/queries/funnels/test/test_funnel_unordered.py @@ -41,14 +41,14 @@ def _create_action(**kwargs): class TestFunnelUnorderedStepsBreakdown( ClickhouseTestMixin, - funnel_breakdown_test_factory( + funnel_breakdown_test_factory( # type: ignore ClickhouseFunnelUnordered, ClickhouseFunnelUnorderedActors, _create_event, _create_action, _create_person, ), -): # type: ignore +): maxDiff = None def test_funnel_step_breakdown_event_single_person_events_with_multiple_properties(self): @@ -641,13 +641,13 @@ def test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step(self): class TestFunnelUnorderedStepsConversionTime( ClickhouseTestMixin, - funnel_conversion_time_test_factory( + funnel_conversion_time_test_factory( # type: ignore ClickhouseFunnelUnordered, ClickhouseFunnelUnorderedActors, _create_event, _create_person, ), -): # type: ignore +): maxDiff = None pass diff --git a/posthog/test/base.py b/posthog/test/base.py index af4a7f5ead02b..105285fa3073e 100644 --- a/posthog/test/base.py +++ b/posthog/test/base.py @@ -425,7 +425,11 @@ def fn_with_materialized(self, *args, **kwargs): materialize("person", prop) materialize("events", prop, table_column="person_properties") for group_type_index, prop in group_properties: - materialize("events", prop, table_column=f"group{group_type_index}_properties") # type: ignore + materialize( + "events", + prop, + table_column=f"group{group_type_index}_properties", # type: ignore + ) try: with self.capture_select_queries() as sqls: