Comments (2)
I have to say I find all this focus on indentation aids a little disconcerting. If I had found microsoft/vscode-python#6333 (or microsoft/vscode-python#6497) earlier, I would have commented there.
I had kind of thought that once the fancy continuation-line indentation was finished, we were really done with automatic indentation.
Note that in Python, this is perfectly legal:
if foo:
if bar:
print('foobar')
else:
print('not foo')
One of the consequences of not having suite-ending delimiters is that it is impossible to infer, even in principle, what the "proper" indentation level is for else
when there are multiple outstanding antecedent if
statements. It's entirely up to the programmer to specify it. (In microsoft/vscode-python#6333, Brett cites the auto-dedent for else
in Ruby. But Ruby has the end
keyword, so the situation is different.)
I would appeal to the Python sensibility of refusing the temptation to guess.
Please tell me that whatever is being done with auto-dedentation of else
and friends, it only happens when the keyword in question appears at the same indentation level as the previous line.
For example, let's say I've already typed the following, and the cursor is on the next line, aligned with print
:
if foo:
if bar:
print('foobar')
#<--cursor is here
And let's say I want an else
on that 4th line. Because I am a conscientious programmer (which I believe most are, by the way), I am not going to just type else
right there; I'm going to dedent first, manually. Let's say what I want to achieve is this:
if foo:
if bar:
print('foobar')
else:
print('foo')
Now, recall I said I dedented manually. Please tell me that the plan is not for automatic dedent to kick in when I type the else
and move it another level to the left.
Or, let's say I want to achieve the following:
if foo:
if bar:
print('foobar')
else:
print('not foo')
Again, after typing print('foobar')
and Enter, I'm going to manually dedent two levels. Please reassure me that my carefully positioned else
is not going to be automatically shifted to the right because some overly guessy algorithm thinks it is meant to correspond to the most recent if
.
I am sort of OK with the editor automatically dedenting else
one level if it isn't already dedented one or more levels. Because then the editor would at least be converting definitely-invalid code into valid-and-possibly-even-intended code. It's definitely not OK to convert already valid code into code that means something else (which is what is happening in microsoft/vscode-python#6886, and why that issue has so much attention; indeed, that is how I found this one).
from pylance-release.
Note that solving this specific issue will require context-aware whitespace formatting.
from pylance-release.
Related Issues (20)
- ERROR HOT 1
- issue. HOT 1
- Inline suggestions not working if bracket not closed HOT 3
- Pylance from time to time crash (when ssh to remove repo). HOT 3
- why my pythons speak function not working HOT 1
- Python Syntax Highlighting Issue HOT 1
- Select a different interpreter does not work in the conda environment
- Bulleted lists with sub bullets don't display the sub-bullets correctly indented HOT 1
- Docstrings initially render incorrectly HOT 2
- Docstring rst table indentation does not work
- rst docstring does not display urls HOT 1
- Wrong "Expected no arguments to <Flask SQL Alchemy> constructor" HOT 2
- Clarification on interaction between python.analysis.exclude and indexing of venv HOT 2
- Allow toggling fstring using keyboard shortcut (vscode command)
- pylance issues HOT 1
- Pylance + VS Code - Inline Quick Suggestions swapping with each keypress HOT 1
- Python's in operator should support type checking HOT 1
- Pylance not narrowing Value-Constrained Type Variables after Type Guard
- Pylance issue HOT 1
- Pylance Infinite "Files to Analyze" Slowing Other Features like Quick Fix - VSCode HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylance-release.