From e859b1d3124fa07593785c0157f1805beb109125 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 22 Dec 2025 19:00:38 +0530 Subject: [PATCH] fix: disable UP040, revert some instances to TypeAlias Signed-off-by: Akhil Narang --- frappe/model/workflow.py | 7 +++++-- frappe/types/filter.py | 22 ++++++++++------------ frappe/utils/__init__.py | 2 +- pyproject.toml | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/frappe/model/workflow.py b/frappe/model/workflow.py index 4658d04d40..d089f75a62 100644 --- a/frappe/model/workflow.py +++ b/frappe/model/workflow.py @@ -1,8 +1,11 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: MIT. See LICENSE + +from __future__ import annotations + import json from collections import defaultdict -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING import frappe from frappe import _ @@ -40,7 +43,7 @@ def get_workflow_name(doctype): @frappe.whitelist() def get_transitions( - doc: "Document" | str | dict, workflow: "Workflow" = None, raise_exception: bool = False + doc: Document | str | dict, workflow: Workflow = None, raise_exception: bool = False ) -> list[dict]: """Return list of possible transitions for the given doc""" from frappe.model.document import Document diff --git a/frappe/types/filter.py b/frappe/types/filter.py index 1c4b4b9c85..acf9369322 100644 --- a/frappe/types/filter.py +++ b/frappe/types/filter.py @@ -8,20 +8,20 @@ from typing import Any, NamedTuple, Self, TypeAlias, TypeGuard, TypeVar, cast, o from pypika import Column -type Doct = str -type Fld = str -type Op = str -type DateTime = datetime | date -type _Value = str | int | float | None | DateTime | Column -type _InputValue = _Value | bool -type Value = _Value | Sequence[_Value] -type InputValue = _InputValue | Sequence[_InputValue] +Doct: TypeAlias = str +Fld: TypeAlias = str +Op: TypeAlias = str +DateTime: TypeAlias = datetime | date +_Value: TypeAlias = str | int | float | None | DateTime | Column +_InputValue: TypeAlias = _Value | bool +Value: TypeAlias = _Value | Sequence[_Value] +InputValue: TypeAlias = _InputValue | Sequence[_InputValue] -type FilterTupleSpec = ( +FilterTupleSpec: TypeAlias = ( tuple[Fld, InputValue] | tuple[Fld, Op, InputValue] | tuple[Doct, Fld, Op, InputValue] ) -type FilterMappingSpec = Mapping[Fld, _InputValue | tuple[Op, InputValue]] +FilterMappingSpec: TypeAlias = Mapping[Fld, _InputValue | tuple[Op, InputValue]] class Sentinel: @@ -35,8 +35,6 @@ class Sentinel: UNSPECIFIED = Sentinel() -T = TypeVar("T") - def is_unspecified[T](value: T | Sentinel) -> TypeGuard[Sentinel]: return value is UNSPECIFIED diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index fc86783fe7..b9d444a94d 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -46,7 +46,7 @@ EMAIL_MATCH_PATTERN = re.compile( UNSET = object() -type PropertyType = property | functools.cached_property +PropertyType: TypeAlias = property | functools.cached_property def get_fullname(user=None): diff --git a/pyproject.toml b/pyproject.toml index cb2cb2ff26..4b202ff483 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -190,6 +190,7 @@ ignore = [ "UP031", # Use format specifiers instead of percent format "UP032", # Use f-string instead of `format` call (translations) "UP037", # quoted annotations + "UP040", # Use type aliases instead of type annotations ] typing-modules = ["frappe.types.DF"]