Files
openide/python/testData/paramInfo/AnnotatedDecoratorAddsParametersToOriginalFunctionWithConcatenate.py
Mikhail Golubev 9300fe8c45 PY-60104 Clean up in tests about type inference for decorators
Removed a number of tests in Py3TypeTest duplicating those of PyDecoratedFunctionTypeProviderTest.

Removed the tests about PY-23067 in Py3ArgumentListInspectionTest and Py3CompletionTest because
this issue was actually not addressed in 05e8ed4df0c7faa24bd972e1b422f664d708b510, and the behavior
some of them assert is not what users wanted.

More consistent naming of tests in PyDecoratedFunctionTypeProviderTest and PyParameterInfoTest.
Removed there excess tests too similar to others or checking scenarios not relevant to
the current approach to type inference for decorators, e.g. presense of @functools.wraps and
alternatives inside decorators — we don't even analyze their bodies anymore.

Add a few extra tests illustrating problems with the current approach:
- testNotAnnotatedDecoratorChangingFunctionSignatureIsIgnored
- testInStackOfDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testInStackOfImportedDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testNotAnnotatedDecoratorRetainsParametersOfOriginalFunctionEvenIfItChangesItsSignature

GitOrigin-RevId: 0bf5070fc523b88dcc9d3009786dd028bdfa0feb
2024-01-09 20:49:13 +00:00

23 lines
504 B
Python

import functools
from typing import Callable, ParamSpec, TypeVar, Concatenate
P = ParamSpec("P")
R = TypeVar("R")
def decorator(func: Callable[P, R]) -> Callable[Concatenate[str, P], R]:
@functools.wraps(func)
def wrapper(input_c: str, input_a: int, input_b: float):
print("using_decorator")
return func(input_a, input_b)
return wrapper
@decorator
def function(input_a: int, input_b: float):
return input_a + input_b
if __name__ == '__main__':
function(<arg1>)