You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Typing: av.open() as context manager to populate variables for later use results in 'possibly unbound' #2053
The issue seems that the typechecker doesn't know whether an exception will be raised that both (a) prevents variable assignment and (b) is later suppressed in the course of the context manager's execution. This suppression of a raised error could make any variables that were created by assignments in the context manager unbound, so the typechecker is trying to be conservative.
Proposed solution
The typing spec mentions that typecheckers must be able to distinguish between context managers that can suppress exceptions from those that can't; the spec says that the context manager's __exit__ method return type is used for this purpose; to signal that the context manager will not suppress exceptions (which, judging by av/container/core.pyx, is the case for with av.open()...) the __exit__ method type should not be bool or Literal[True]. The Cython code in core.pyx seems to show the actual return type is None, but the specified return type in core.pyi for Container.__exit__() is bool.
Can we change the Container.__exit__ return type in core.pyi from bool to None? Thanks!
changed the title [-]Using av.open() as context manager to populate variables for later use results in 'possibly unbound' at use time[/-][+]Typing: av.open() as context manager to populate variables for later use results in 'possibly unbound'[/+]on Dec 17, 2025
Activity
Fix #2053
Fix PyAV-Org#2053
[-]Using av.open() as context manager to populate variables for later use results in 'possibly unbound' at use time[/-][+]Typing: av.open() as context manager to populate variables for later use results in 'possibly unbound'[/+]