A better way is to admit you have two different functions:
# myfunc(3)
async def myfunc1(x: int) -> X:
...
# myfunc("all")
async def myfunc2() -> X:
...
Now you don't have the problem of passing another string aside from "all", because you no longer have a function that accepts any string.
An aside
Since Python is a dynamically typed language, the rest of this answer will assume we are using code the successfully passes static type-checking; we assume that calls like myfunc1("not an int") are just as incorrect as myfunc2(3).)
There was never nothing special about the specific string "all"; you could have used "every" or "each" or "foo", and you would have structured the code the same way. The important thing was that "all" wasn't any other string: you really just wanted a single value that wasn't an int.
Taking the point further, why would you care if the caller passed any other string than "all"? Rather than raise an exception, you could just as easily have written
if para != "all":
para = "all"
and proceeded.
None fills that role more cleanly: it's the only value of its type, so there's no possibility of passing an incorrect value. Now look at the following function:
async def myfunc2a(x: None) -> X:
...
There is only one legal way to call this function: myfunc2a(None). None isn't filling any semantic role here; it's there purely for syntactic reasons, because myfunc2a needs an argument. When that's the case, you might as well just eliminate the parameter altogether (which is legal in Python, unlike mathematical functions which are by definition mappings from an argument to a value).
async def myfunc2b() -> X:
...
Union[int, Literal["all"]].myfuncis "basically" a function on integers, what does the exception"all"mean? There might be a better API design that sidesteps the issue altogether."all"to call the function. If somebody else is giving the caller either anintor the string"all"and the caller is just passing it on, then yes, the problem should be moved further up. Otherwise you have a "stringly typed" program.