0

The title may be confusing so I will explain it. I run python on replit.com (not sure if this is only an issue on replit.com) and sometimes when I hide then unhide code within a function it automatically puts code that's next to but not within the function inside the function. Sometimes it does this but other times it doesn't and I don't understand its reasoning. Let me show you an example:

def f(x): # Collapsed Function

# Comment (outside of function)

I open the function

def f(x): # Open Function
     print("Function is open")

# Comment (outside of function)

Then I close it

def f(x): # Closed Function

Then I reopen it

def f(x): # Open Function
     print("Function is open")
# Comment (Inside Function)

What's more odd is that the comment isn't indented yet the code acts as if the comment is within the function. This isn't the only occurrence. So here is my question: Why does this occur and how can I prevent this from happening again?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Pretty sure this is just a replit problem; I've never had this problem before on VSC. Not really python-related – bobtho'-' Sep 23 '22 at 20:59
  • 1
    you must understand, this has nothing to do with Python, this is something directly related to whatever text-editor/IDE you are using – juanpa.arrivillaga Sep 23 '22 at 21:00
  • 1
    If there's a bug with replit.com, you should report it. There's a 'Report a bug' button in the lower left '?' menu. This has nothing to do with Python and is not a question for StackOverflow. It's just a problem with a free online editor. (I was able to reproduce the issue, it always happens if there's a comment with a line break right after a function - some bug in the code deciding what is part of the function) – Grismar Sep 23 '22 at 21:04
  • Thank you for the feedback. I will report this to replit.com. – 117Degrees Sep 23 '22 at 21:07
  • Comments don't follow indentation rules in Python. repl.it has to guess which function the comment is related to, and it's guessing wrong. – Barmar Sep 23 '22 at 21:33

0 Answers0