最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

syntax - What is the keyword argument shortcut reported by Pylance that requires Python 3.14? - Stack Overflow

programmeradmin0浏览0评论

I was just typing some code with pylance/pyright and an error/information about a new feature poped-up, rather than reporting an SyntaxError.

def foo(x): ...

foo(x=)  # underlines = and reports:

Keyword argument shortcut requires Python 3.14 or newer (Pylance)

This raises the question: What is Python keyword argument shortcut that pyright mentions?

I was just typing some code with pylance/pyright and an error/information about a new feature poped-up, rather than reporting an SyntaxError.

def foo(x): ...

foo(x=)  # underlines = and reports:

Keyword argument shortcut requires Python 3.14 or newer (Pylance)

This raises the question: What is Python keyword argument shortcut that pyright mentions?

Share Improve this question edited Mar 28 at 18:38 Daraan asked Mar 28 at 10:34 DaraanDaraan 4,2227 gold badges22 silver badges47 bronze badges 11
  • 1 The PEP in question is rejected, it says so in the post you linked in your answer ("we have decided to reject the PEP"). Not sure why you think a rejected proposal, which will NOT get implemented, needs a self-answered SO question. – l4mpi Commented Mar 28 at 10:41
  • @l4mpi I think that's a question for Pyright, not the OP. (Why did a tool address a proposed feature in the first place?) – chepner Commented Mar 28 at 11:20
  • @chepner that sounds like a bug / not-so-smart-choice by pyright. Maybe this should be a bug report to pyright, but I still don't see why this should be an SO question. Why a project chooses to add or not add some feature (or rather, bug, in this case) is a question about the project leadership and not in scope for SO. – l4mpi Commented Mar 28 at 11:44
  • 1 It's a tool in the wild that claims Python 3.14 is required for a presumed feature. Whatever the status of the PEP, it's a question that could legitimately come up for a user of the tool. – chepner Commented Mar 28 at 11:52
  • 2 If someone were to see that and wonder what it meant, yes. I also agree that Pyright should not have done this, but I don't expect everybody using Pyright to know the backstory (or even existence) of PEP 736. "File bug report" and "ask on SO" aren't mutually exclusive courses of action. – chepner Commented Mar 28 at 13:09
 |  Show 6 more comments

1 Answer 1

Reset to default 1

The idea of keyword argument shortcut or "Shorthand syntax for keyword arguments at invocation" is that foo(x=) is equivalent to foo(x=x), i.e. one saves double typing the same variable name.

A parallel could be seen in f-string interpolation where f'{x=}' is expanded to f'x={x}'.

Its proposal is PEP 736 which is in the Draft stage.


However, it might not come. The steering council commented a result of their discussion in the respective discuss thread about PEP 736.

[...] the cost versus benefit of the new syntax does not have a high enough payoff to justify the added complexities and maintenance [...]

发布评论

评论列表(0)

  1. 暂无评论