-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
https://docs.astral.sh/ruff/rules/non-self-return-type/
Very similar to #14183
I feel like logically a fix for this rule should be feasible without too much complexity? (at least in pyi files and maybe py files above 3.10, see #9761). The fix should be unsafe as there might be a specific intent, or a stub shows that the runtime returns an instance not actually based on self/cls. Marking it unsafe may also simplify the logic to apply the fix (if Self already exists in scope).
Maybe it can be restricted to where the return type to replace is the same as the class and not overloaded ?
class ArrayDerivative(Derivative):
def __new__(cls, expr, *variables, **kwargs) -> ArrayDerivative: ... # unsafe autofix to replace with selfclass CaptureOutput:
@overload
def __new__(
cls, backend: Literal[CaptureOutputs.PIL] = CaptureOutputs.PIL
) -> PILCaptureOutput: ...
@overload
def __new__(cls, backend: Literal[CaptureOutputs.NUMPY]) -> NumpyCaptureOutput: ...
@overload
def __new__(cls, backend: Literal[CaptureOutputs.NUMPY_FLOAT]) -> NumpyFloatCaptureOutput: ...
@overload
def __new__(cls, backend: Literal[CaptureOutputs.PYTORCH]) -> PytorchCaptureOutput: ...
@overload
def __new__(
cls, backend: Literal[CaptureOutputs.PYTORCH_FLOAT]
) -> PytorchFloatCaptureOutput: ...
@overload
def __new__(cls, backend: Literal[CaptureOutputs.PYTORCH_GPU]) -> PytorchGPUCaptureOutput: ...
@overload
def __new__(
cls, backend: Literal[CaptureOutputs.PYTORCH_FLOAT_GPU]
) -> PytorchFloatGPUCaptureOutput: ...
@overload
def __new__(cls, backend: CaptureOutputs) -> CaptureOutput: ...
def __new__(cls, backend: CaptureOutputs = CaptureOutputs.PIL) -> CaptureOutput: # no autofix
return cls._initialize_backend(backend)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violations