I have a function that takes a single string arg.
I think in my first post of this issue I was not clear enought.
The purpose of this question is to figure how how to get typing (autocomplete) support for such methods without using cast.
doc = CreateScritpService("Calc")
To get the type I use cast.
doc = cast(SFDocuments.SF_Calc, CreateScritpService("Calc"))
bas = cast(SFScriptForge.SF_Basic, CreateScriptService("Basic"))
I am the Author of ScriptForge Typings
An I am looking for a way to automatically have CreateScritpService
return the correct type based upon the string input arg.
Is this possible?
Advertisement
Answer
You can achieve this using overload
along with Literal
, something like this:
JavaScript
x
10
10
1
from typing import Literal, overload
2
3
@overload
4
def CreateScriptService(x: Literal["Calc"]) -> SFDocuments.SF_Calc:
5
6
7
@overload
8
def CreateScriptService(x: Literal["Basic"]) -> SFScriptForge.SF_Basic:
9
10