From 1efb8b90ba3a554897e83a6c06837ccb1acd575e Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 2 Nov 2023 14:46:42 -0400 Subject: [PATCH] temp2 --- scripts-dev/mypy_synapse_plugin.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/scripts-dev/mypy_synapse_plugin.py b/scripts-dev/mypy_synapse_plugin.py index 4830c45432..76a81c8612 100644 --- a/scripts-dev/mypy_synapse_plugin.py +++ b/scripts-dev/mypy_synapse_plugin.py @@ -103,9 +103,29 @@ def cached_function_method_attribute(ctx: AttributeContext) -> mypy.types.Type: ctx.default_attr_type.type.fullname == "synapse.util.caches.descriptors.CachedFunction" ): + if getattr(ctx.context, "name") == "did_forget": + breakpoint() + # Unwrap the wrapped function. - return _unwrap_cached_decoratored_function( - ctx.default_attr_type.args[0], ctx.api + wrapped_signature = ctx.default_attr_type.args[0] + assert isinstance(wrapped_signature, CallableType) + + # 1. Mark this as a bound function signature. + signature: CallableType = bind_self(wrapped_signature) + + # 4. Ensure the return type is a Deferred. + ret_arg = _get_true_return_type(signature) + + # This should be able to use api.named_generic_type, but that doesn't seem + # to find the correct symbol for anything more than 1 module deep. + # + # modules is not part of CheckerPluginInterface. The following is a combination + # of TypeChecker.named_generic_type and TypeChecker.lookup_typeinfo. + sym = ctx.api.modules["twisted.internet.defer"].names.get("Deferred") # type: ignore[attr-defined] + ret_type = Instance(sym.node, [remove_instance_last_known_values(ret_arg)]) + + return ctx.default_attr_type.copy_modified( + args=[signature.copy_modified(ret_type=ret_type)] ) return ctx.default_attr_type