Skip to content

False positive for WPS430 with whitelisted name #3589

@sobolevn

Description

@sobolevn
def wrap_handler(
    method: _MethodSyncHandler | _MethodAsyncHandler,
) -> SyncErrorHandlerT | AsyncErrorHandlerT:
    if inspect.iscoroutinefunction(method):

        @wraps(method)
        async def decorator(
            endpoint: 'Endpoint',
            controller: 'Controller[BaseSerializer]',
            exc: Exception,
        ) -> HttpResponse:
            return await method(  # type: ignore[no-any-return]
                controller.active_blueprint,
                endpoint,
                controller,
                exc,
            )

    else:

        @wraps(method)
        def decorator(
            endpoint: 'Endpoint',
            controller: 'Controller[BaseSerializer]',
            exc: Exception,
        ) -> HttpResponse:
            return method(  # type: ignore[return-value]
                controller.active_blueprint,
                endpoint,
                controller,
                exc,
            )

    return decorator

This code falsy raises two WPS430 violations.

  69:9     WPS430 Found nested function: factory
  async def factory(
  ^

  84:9     WPS430 Found nested function: factory
  def factory(
  ^

But, the name is correct. decorator name is in whitelist of names. This is a false positive.
We need to fix it and add a test case.

Metadata

Metadata

Labels

bugSomething isn't workinggood first issueEntrypoint to the projecthelp wantedExtra attention is neededlevel:starterGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions