diff --git a/frappe/__init__.py b/frappe/__init__.py index 5a03438a9e..5efdfd8ce9 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -17,7 +17,7 @@ import json import os import re import warnings -from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, overload +from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, TypeAlias, overload import click from werkzeug.local import Local, release_local @@ -1142,7 +1142,42 @@ def get_cached_value( return values -def get_doc(*args, **kwargs) -> "Document": +_SingleDocument: TypeAlias = "Document" +_NewDocument: TypeAlias = "Document" + + +@overload +def get_doc(document: "Document", /) -> "Document": + pass + + +@overload +def get_doc(doctype: str, /) -> _SingleDocument: + """Retrieve Single DocType from DB, doctype must be positional argument.""" + pass + + +@overload +def get_doc(doctype: str, name: str, /, for_update: bool | None = None) -> "Document": + """Retrieve DocType from DB, doctype and name must be positional argument.""" + pass + + +@overload +def get_doc(**kwargs: dict) -> "_NewDocument": + """Initialize document from kwargs. + Not recommended. Use `frappe.new_doc` instead.""" + pass + + +@overload +def get_doc(documentdict: dict) -> "_NewDocument": + """Create document from dict. + Not recommended. Use `frappe.new_doc` instead.""" + pass + + +def get_doc(*args, **kwargs): """Return a `frappe.model.document.Document` object of the given type and name. :param arg1: DocType name as string **or** document JSON.