Title: `SyntaxError: parameter without a default follows parameter with a default` is inaccurate · Issue #129545 · python/cpython · GitHub
Open Graph Title: `SyntaxError: parameter without a default follows parameter with a default` is inaccurate · Issue #129545 · python/cpython
X Title: `SyntaxError: parameter without a default follows parameter with a default` is inaccurate · Issue #129545 · python/cpython
Description: Bug report Bug description: The problem Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected: >>> def f(a=1, b): File "
Open Graph Description: Bug report Bug description: The problem Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected: >>> def f(a=1, b): Fi...
X Description: Bug report Bug description: The problem Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected: >>> def f(a=...
Opengraph URL: https://github.com/python/cpython/issues/129545
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`SyntaxError: parameter without a default follows parameter with a default` is inaccurate","articleBody":"# Bug report\n\n### Bug description:\n\n#### The problem\n\nTrying to define a function in which a positional parameter follows a parameter with a default value, we get a `SyntaxError` as expected:\n\n```pycon\n\u003e\u003e\u003e def f(a=1, b):\n File \"\u003cpython-input-0\u003e\", line 1\n def f(a=1, b):\n ^\nSyntaxError: parameter without a default follows parameter with a default\n```\n\nBut the message that comes with it is not as accurate as it could be, as we can easily construct a valid function signature in which a parameter without a default follows a parameter with a default so long as both are keyword-only parameters:\n\n```pycon\n\u003e\u003e\u003e def f(*, a=1, b):\n... pass\n... \n\u003e\u003e\u003e \n```\n\n(I didn't use `a=1, *, b` for this counterexample because then one could argue that, if \"follows\" is interpreted as \"follows _immediately_\", we did resolve the situation described in the error message, making it formally accurate, albeit confusing.)\n\n#### Proposed fix\n\nSo, in my opinion, the message should be changed to something more like `positional parameter without a default follows parameter with a default`, reflecting the true nature of the problem.\n\n#### Other benefits\n\nIt's not _just_ a matter of accuracy for accuracy's sake, however: This change would also hint to people who don't know or have forgotten about keyword-only parameters that there is another possibility of resolving the issue than the ones implied by the current message.\n\n#### Additional context\n\n- As a result of https://github.com/python/cpython/issues/91210, the error message was changed from `non-default argument follows default argument` to the one above starting in Python 3.12 (via https://github.com/python/cpython/pull/95933). So there is precedent for changing this message to make it more accurate.\n- Keyword-only parameters were introduced in Python 3.0 with [PEP 3102](https://peps.python.org/pep-3102/), which makes me think I must be missing some obvious reason why their consequences can't be reflected in the error message.\n- `dataclasses` has an exception message with the same issue, but as that one also still has the \"argument\" vs \"parameter\" issue mentioned above, it's probably appropriate to create a separate ticket for that.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-130937\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/smheidrich","@type":"Person","name":"smheidrich"},"datePublished":"2025-02-01T11:45:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/129545/cpython/issues/129545"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f3789a12-7483-9b84-5b00-e4d49406c28e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E880:33B318:15DDC15:1C383DB:6A5C5676 |
| html-safe-nonce | cd98f71c0311e4cd78ac88aa81584be18a870c713c9759e9e758ef4d2447f286 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODgwOjMzQjMxODoxNUREQzE1OjFDMzgzREI6NkE1QzU2NzYiLCJ2aXNpdG9yX2lkIjoiNTA5MzY1NDUzNTk0NTgwNTk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | eb228e9f46d7051d4584edec79bf190d464d53bdf1f6e84968978f6ddefaa038 |
| hovercard-subject-tag | issue:2825164149 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/129545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e6ec32ec0f7cf40fefa7b7832380f896fba1c25cd942db27238c2c34d54a33d9/python/cpython/issues/129545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e6ec32ec0f7cf40fefa7b7832380f896fba1c25cd942db27238c2c34d54a33d9/python/cpython/issues/129545 |
| og:image:alt | Bug report Bug description: The problem Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected: >>> def f(a=1, b): Fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | smheidrich |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width