Open
Conversation
Make foldings in Python happen only when colon is at the end on the line (to prevent folding in the middle of the definition of a function while using type-hints)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, in Python, when we have type-hints in the definition of a function, the folding occurs on the first colon.
Folding the following function:
will result in only showing
def some_function(arg:...Just updating the rule of the parser to check if the colon is at the end of the line fixes the issue, allowing to show the full function definition,
def some_function(arg: ArgType) -> ReturnType:which is far more appreciable in my opinion.I believe the only cases in Python where we have a colon that is not at the end of the line is the situation described above, where we are hinting the type of a parameter, and the definition of entries in a dictionary, so this modification should not break anything (but I might be mistaken).
The only case I could think of that breaks this is if we add a comment after the colon at the end of the line, but I don't think this really causes an issue.