diff --git a/frappe/core/doctype/report/report.py b/frappe/core/doctype/report/report.py index ae862184b6..e87292f55c 100644 --- a/frappe/core/doctype/report/report.py +++ b/frappe/core/doctype/report/report.py @@ -2,6 +2,7 @@ # License: MIT. See LICENSE import datetime import json +from typing import Union import frappe import frappe.desk.query_report @@ -326,7 +327,7 @@ class Report(Document): return data @frappe.whitelist() - def toggle_disable(self, disable): + def toggle_disable(self, disable: bool | str | int): if not self.has_permission("write"): frappe.throw(_("You are not allowed to edit the report.")) diff --git a/frappe/tests/test_utils.py b/frappe/tests/test_utils.py index cf6134d101..2e22b28731 100644 --- a/frappe/tests/test_utils.py +++ b/frappe/tests/test_utils.py @@ -919,3 +919,28 @@ class TestMiscUtils(FrappeTestCase): self.assertEqual(safe_json_loads("{}"), {}) self.assertEqual(safe_json_loads("{ /}"), "{ /}") self.assertEqual(safe_json_loads("12"), 12) # this is a quirk + + +class TestTypingValidations(FrappeTestCase): + ERR_REGEX = "^type of .* must be .*; got (object|list) instead$" + + def test_validate_whitelisted_api(self): + from inspect import signature + + whitelisted_fn = next(x for x in frappe.whitelisted if x.__annotations__) + bad_params = (object(),) * len(signature(whitelisted_fn).parameters) + + with self.assertRaisesRegex(TypeError, self.ERR_REGEX): + whitelisted_fn(*bad_params) + + def test_validate_whitelisted_doc_method(self): + report = frappe.get_last_doc("Report") + + with self.assertRaisesRegex(TypeError, self.ERR_REGEX): + report.toggle_disable(["disable"]) + + current_value = report.disabled + changed_value = not current_value + + report.toggle_disable(changed_value) + report.toggle_disable(current_value) diff --git a/frappe/utils/typing_validations.py b/frappe/utils/typing_validations.py index b7708b0a52..b0eae6b7b8 100644 --- a/frappe/utils/typing_validations.py +++ b/frappe/utils/typing_validations.py @@ -1,4 +1,4 @@ -from inspect import _empty, isclass, signature +from inspect import _empty, signature from typing import Callable, ForwardRef, Union from typeguard import check_type