对于 Python3,您应该只使用关键字参数:
文件pylint_args_too_many.py
"""Example of a function causing pylint too-many-arguments"""
def get_car(
manufacturer, model, year=None, registration_number=None, vin=None, color=None
):
"""Returns dict with all required car attributes"""
return dict(
manufacturer=manufacturer,
model=model,
year=year,
registration_number=registration_number,
vin=vin,
color=color,
)
print(repr(get_car(manufacturer="ACME", model="Rocket")))
pylint pylint_args_too_many.py
************* Module pylint_args_too_many
pylint_args_too_many.py:3:0: R0913: Too many arguments (6/5) (too-many-arguments)
------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)
文件pylint_args.py
"""Show how to avoid too-many-arguments"""
def get_car(
*, manufacturer, model, year=None, registration_number=None, vin=None, color=None
):
"""Returns dict with all required car attributes"""
return dict(
manufacturer=manufacturer,
model=model,
year=year,
registration_number=registration_number,
vin=vin,
color=color,
)
print(repr(get_car(manufacturer="ACME", model="Rocket")))
pylint pylint_args.py
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)