-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
sample use casehere to make sure none of these get losthere to make sure none of these get lost
Description
I want to contribute a real life use case that we encountered which may justify the needs of Intersection types.
Can anyone suggest an alternative without using Intersection?
from typing import *
from contextlib import AbstractContextManager, ContextDecorator, contextmanager
@contextmanager
def _hoge():
...
try:
yield
finally:
...
def foo() -> ContextManager[Never] & ContextDecorator: # How should we annotate this without Intersection?
...
return _hoge()
# ====
# foo is used both as ContextManager and ContextDecorator
with foo():
...
@foo()
def bar():
...
NOTE: the spec of @contextmanager
is here:
https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager
Essentially, what the decorated function returns is a ContextManager that uses ContextDecorator mixin.
NeilGirdhar
Metadata
Metadata
Assignees
Labels
sample use casehere to make sure none of these get losthere to make sure none of these get lost