question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting lambda function python

See original GitHub issue

Environment data

  • Version: 1.53.0
  • OS and version: Windows 10 - 10.0.19042
  • Python version: Python 3.9.1
  • Value of the python.languageServer setting: Pylance

I cannot format a document that include a python lambda function without having the formater convert it to a function. Here is the code

double = lambda x: x * 2
print(double(5))

Expected behaviour

double = lambda x: x * 2
print(double(5))

Actual behaviour

def double(x): return x * 2
print(double(5))

Steps to reproduce:

  1. Copy paste the code
  2. Format the document (I use format on Save) loop_lambda_savr_format

Notes

My default formatter is “null”. But it still format great the rest of the code.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
karrtikrcommented, Feb 12, 2021

Oh I see, the formatting comes from autopep8 itself, which is the default formatter.

If you check the output panel,

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

You’ll see that we just run the command calling autopep8. So you’ll need to check their docs on how to configure autopep8 that way, or open an issue in their repo https://github.com/hhatto/autopep8

0reactions
karrtikrcommented, Feb 12, 2021

Great 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Python Lambda Functions
A Python lambda function behaves like a normal function in regard to arguments. Therefore, a lambda parameter can be initialized with a default...
Read more >
Python Lambda - W3Schools
A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression....
Read more >
Python string formatting - Possible use of lambda?
The idea is just using format(*xxx) for calling format with a variable number of arguments. Share.
Read more >
Python Lambda Functions - GeeksforGeeks
Python Lambda Function Syntax · This function can have any number of arguments but only one expression, which is evaluated and returned. ·...
Read more >
Lambda Function In Python - PythonForBeginners.com
In python, we can use lambda functions to replace single-line mathematical statements. For example, we can create a lambda function that takes a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found