Skip to content

Commit

Permalink
Fixed mypi issues or added ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 committed Oct 25, 2023
1 parent 24a5ba8 commit 6927240
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 55 deletions.
12 changes: 6 additions & 6 deletions ee/tasks/send_license_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/data_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions posthog/api/event_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions posthog/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions posthog/api/property_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion posthog/api/test/openapi_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
5 changes: 4 additions & 1 deletion posthog/api/test/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions posthog/models/feature_flag/flag_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions posthog/models/filters/mixins/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions posthog/models/filters/mixins/funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
12 changes: 6 additions & 6 deletions posthog/models/filters/mixins/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion posthog/plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions posthog/queries/actor_base_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions posthog/queries/funnels/test/test_funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions posthog/queries/funnels/test/test_funnel_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions posthog/queries/funnels/test/test_funnel_unordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion posthog/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6927240

Please sign in to comment.