I\'m having a very frustrating issue with PyCharm in that it does not want to properly outline the code so that blocks fold correctly. I\'ve looked all over the place and co
You can use
# region FooRegion
...
your-code-here
...
# endregion
This will create code folding regions manually like in visual studio style
Finally!! I figured out how to remove the invalid folding regions. If you place your cursor on the line that starts an invalid folding block (line 106 in my first example), then right click anywhere in that line and select Folding -> Fold Selection / Remove Region
and that will delete the incorrect folding annotation!
I still have no clue why they are generated in the first place, but at least this is a decent "fix".