RedHatQE / RedHatQE/flake8-plugins

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

Open
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3
Forks
2
Avg merge
12h 55m
Merged PRs (30d)
4

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the FCN001 implementation and its existing tests, then inspect how function parameter kinds are handled. Reproduce the socket.setdefaulttimeout example and add coverage for positional-only parameters. Done means FCN001 no longer requires keyword arguments when the called function cannot accept them.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.