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
Description
FCN001 raises a false positive when calling functions with positional-only parameters, which were introduced in Python 3.8 (PEP 570).
Example
Problem
socket.setdefaulttimeout()has a positional-only parameter signature:The
/syntax means the parameter cannot accept keyword arguments. Attempting to use keywords results in: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
Suggested Fix
Check if parameters are positional-only before enforcing keyword arguments:
Related