This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The staticmethod doesn't properly reject keyword arguments
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: SylvainDe, kayhayen, serhiy.storchaka
Priority: normal Keywords: easy (C)

Created on 2017-07-08 07:00 by kayhayen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2635 merged SylvainDe, 2017-07-08 21:56
Messages (6)
msg297946 - (view) Author: Kay Hayen (kayhayen) Date: 2017-07-08 07:00
Check out this:

python3.6 -c "staticmethod(function=1)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: staticmethod expected 1 arguments, got 0

python3.6 -c "staticmethod()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: staticmethod expected 1 arguments, got 0

python3.6 -c "staticmethod(f=1)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: staticmethod expected 1 arguments, got 0

I believe Python 2.7 behaves the same.

What should happen is more like this:

python3.6 -c "range(f=1)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: range() does not take keyword arguments

While statically optimizing, I came across this as a first. At least "classmethod" behaves the same. I suppose it is because these are not intended for manual use anymore.

I would recommend to fix up the argument parsing to either indicate its rejection of keyword arguments, or to accept "function = " for input (preferred).

Thanks,
Kay Hayen
msg297948 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-08 07:32
This is similar to recently fixed issue30534 and issue30627. The solution is simple as for issue30627.
msg297969 - (view) Author: SylvainDe (SylvainDe) * Date: 2017-07-08 19:23
I have a fix ready but I'll look if other functions using _PyArg_NoKeywords may have the same defect before submitting it.
msg297981 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-09 03:45
New changeset 9648088e6ccd6d0cc04f450f55628fd8eda3784c by Serhiy Storchaka (Sylvain) in branch 'master':
bpo-30878: Fix error message when keyword arguments are passed (#2635)
https://github.com/python/cpython/commit/9648088e6ccd6d0cc04f450f55628fd8eda3784c
msg297982 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-09 03:47
Thank you for your report Kay and thank you for your patch SylvainDe.
msg297988 - (view) Author: SylvainDe (SylvainDe) * Date: 2017-07-09 07:27
Thanks Serhiy Storchaka !

This issue seems to affect (all) other Python versions. Should we proceed to a cherry-pick ?
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75061
2017-07-09 07:27:41SylvainDesetmessages: + msg297988
2017-07-09 03:47:08serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg297982

stage: needs patch -> resolved
2017-07-09 03:45:08serhiy.storchakasetmessages: + msg297981
2017-07-08 21:56:39SylvainDesetpull_requests: + pull_request2700
2017-07-08 19:23:48SylvainDesetmessages: + msg297969
2017-07-08 07:32:21serhiy.storchakasettype: enhancement
versions: + Python 3.7, - Python 3.6
keywords: + easy (C)
nosy: + serhiy.storchaka, SylvainDe

messages: + msg297948
stage: needs patch
2017-07-08 07:00:06kayhayencreate