-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Support type checking from cache_for
decorator
#26052
base: master
Are you sure you want to change the base?
Conversation
…(for better or for worse) or fixing them causes more problems than it solves
cache_key
decoratorcache_for
decorator
cache_for
decoratorcache_for
decorator
current_materialized_column_name = materialized_columns.get((property_name, "properties"), None) | ||
if current_materialized_column_name is not None and current_materialized_column_name != property_name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been broken for a while
posthog/year_in_posthog/year_in_posthog.py:0: error: Item "None" of "dict[Any, Any] | None" has no attribute "get" [union-attr] | ||
posthog/year_in_posthog/year_in_posthog.py:0: error: Argument 1 to "stats_for_user" has incompatible type "dict[Any, Any] | None"; expected "dict[Any, Any]" [arg-type] | ||
posthog/year_in_posthog/year_in_posthog.py:0: error: Item "None" of "dict[Any, Any] | None" has no attribute "get" [union-attr] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are already "handled" here and don't want to fix them
posthog/posthog/year_in_posthog/year_in_posthog.py
Lines 130 to 135 in ff2271b
except Exception as e: | |
capture_exception(e) | |
logger.error("year_in_posthog_2023_error_rendering_2023_page", exc_info=True, exc=e, data=data or "no data") | |
template = get_template("hibernating.html") | |
html = template.render({"message": "Something went wrong 🫠"}, request=request) | |
return HttpResponse(html, status=500) |
@@ -333,12 +333,14 @@ ee/billing/billing_manager.py:0: error: Incompatible types in assignment (expres | |||
posthog/models/property/util.py:0: error: Incompatible type for lookup 'pk': (got "str | int | list[str]", expected "str | int") [misc] | |||
posthog/models/property/util.py:0: error: Argument 3 to "format_filter_query" has incompatible type "HogQLContext | None"; expected "HogQLContext" [arg-type] | |||
posthog/models/property/util.py:0: error: Argument 3 to "format_cohort_subquery" has incompatible type "HogQLContext | None"; expected "HogQLContext" [arg-type] | |||
posthog/models/property/util.py:0: error: Invalid index type "tuple[str, str]" for "dict[tuple[str, Literal['properties', 'group_properties', 'person_properties']], str]"; expected type "tuple[str, Literal['properties', 'group_properties', 'person_properties']]" [index] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't particularly problematic and trying to fix them just moves the errors up the stack to all the call sites instead and don't want to deal with them right now
Problem
cache_for
is a type checking black hole.This makes it easy to introduce errors when refactoring things like
get_materialized_columns
which use the decorator.Changes
cache_for
so that parameters and return types can be type checked.CachedFunction
class because mypy doesn't like it when you stuff additional attributes onto function types.Does this work well for both Cloud and self-hosted?
Yes.
How did you test this code?
mypy