Formatting lambda function python
See original GitHub issueEnvironment 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:
- Copy paste the code
- Format the document (I use format on Save)
Notes
My default formatter is “null”. But it still format great the rest of the code.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh I see, the formatting comes from autopep8 itself, which is the default formatter.
If you check the output panel,
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)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
Great 😃