Skip to content

FCN001: False positive for positional-only parameters (Python 3.8+) #16

@rlobillo

Description

@rlobillo

Description

FCN001 raises a false positive when calling functions with positional-only parameters, which were introduced in Python 3.8 (PEP 570).

Example

import socket
socket.setdefaulttimeout(30)  # FCN001 error: function should be called with keywords arguments

Problem

socket.setdefaulttimeout() has a positional-only parameter signature:

>>> import inspect
>>> inspect.signature(socket.setdefaulttimeout)
(object, /)

The / syntax means the parameter cannot accept keyword arguments. Attempting to use keywords results in:

>>> socket.setdefaulttimeout(timeout=30)
TypeError: _socket.setdefaulttimeout() takes no keyword arguments

Expected Behavior

FCN001 should detect positional-only parameters (where param.kind == inspect.Parameter.POSITIONAL_ONLY) and not require keyword arguments for those functions.

Actual Behavior

FCN001 raises an error even when using keyword arguments would cause a TypeError.

Environment

  • Python: 3.14.0b2 (also affects 3.8+)
  • flake8-plugins: v1.0.0

Suggested Fix

Check if parameters are positional-only before enforcing keyword arguments:

import inspect

sig = inspect.signature(func)
for param in sig.parameters.values():
    if param.kind == inspect.Parameter.POSITIONAL_ONLY:
        # Skip keyword argument check for positional-only params
        continue

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions