I genuinely cannot find an answer to this and related questions on here (such as 1, 2) are for NamedTuple
from the typing
module.
How do I type hint this functions return value please?
from collections import namedtuple
def filename_strip(filepath: str) -> tuple[str, str]:
FileValues = namedtuple("FileValues", "path_without_file filename_with_ext")
(path_without_file, filename_with_ext) = os.path.split(filepath)
return FileValues(path_without_file, filename_with_ext)
I know tuple
is correct as it is returning a tuple but I want my code to be precise for mypy
and do not know if namedtuple
has a different way of type hinting, I could not see anything in the documentation online.