Which type hint to use when assigning ffmpeg.input(Path(..)) to variable, and its following operations?

I have function that uses ffmpeg-python package’s ffmpeg module for processing video and audio content. When applying ffmpeg package to my code, I find I am not sure which type hint should be assigned to the variable created in my code. An example is the following code

class MyWrapper:
    def __init__(self, media_path: Path) -> None:
        self.inner = ffmpeg.input(str(media_path))
    def gen(self, dest_path: Path) -> None: 
        out = self.inner.output(str(dest_path))
        out.run()

The code can be executed and produce correct result. However, I don not know which type hint should be given to self.inner and out variables. Assigning self.inner to ffmpeg, VScode will complains module can not be used as type.If assigning self.inner to Stream, the following line self.inner.output() will be highlighted with an error Cannot access attribute "output" for class "Stream" Attribute "output" is unknown. Any advice or suggestions? Thanks.

I think Stream for self.inner is likely correct (or FilterableStream to be slightly more specific). However, ffmpeg-python does not include type hints directly (git issue), so VSCode attempts to infer what it can. In this case, the output function is attached to FilterableStream at runtime rather than in the class decoration (see here).

Here is a simple example of what’s going on:

class Foo:
    ...

def add_func(func):
    setattr(Foo, func.__name__, func)
    return func

@add_func
def bar(self) -> None:
    print("Bar")

f = Foo()
f.bar() # Cannot access attribute "bar" for class "Foo"

Since type checkers aren’t expected to execute module code (and instead rely on static analysis), VSCode doesn’t know that Foo gained a function called bar.

If instead we defined bar “normally” like

class Foo:
    def bar(self) -> None:
        print("Bar")

Then VSCode can statically know bar is a function on Foo objects via AST parsing.

(An aside, if you just want to silence the warning, you can always use # type: ignore. Doesn’t help if you are looking for better auto complete)