internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: microsoft/ptvsd

Issue:
Tooltip hangs when expanding sys.modules
![image](https://user-images.githubusercontent.com/3840081/37120086-342e50e2-220e-11e8-8044-5ce72ad0f6b6.png)

For VS there is a 'timeout' field that is set (for evaluate, variable enumeration, etc), and this must be honored to have better UI experience. See this request for example:
```
 1> [DebugAdapter] --> C (variables-11): {"command":"variables","arguments":{"variablesReference":12,"timeout":5000},"seq":11,"type":"request"}
```


Discussion:

Resolving patch:
diff --git a/ptvsd/untangle.py b/ptvsd/untangle.py
--- a/ptvsd/untangle.py
+++ b/ptvsd/untangle.py
@@ -185,7 +185,11 @@ def parse(filename, **parser_features):
         parser.setFeature(getattr(handler, feature), value)
     sax_handler = Handler()
     parser.setContentHandler(sax_handler)
-    if is_string(filename) and (os.path.exists(filename) or is_url(filename)):
+    try:
+        is_filename = is_string(filename) and (os.path.exists(filename) or is_url(filename))
+    except ValueError:
+        is_filename = False
+    if is_filename:
         parser.parse(filename)
     else:
         if hasattr(filename, 'read'):


Test patch:
Repository: microsoft/ptvsd

Issue:
Cython speedup extension is not found
This is on Python 3.6 32-bit - the following message is printed when debugging starts:
```
warning: Debugger speedups using cython not found. Run '"C:\Python\3.6-32\python.exe" "C:\Python\3.6-32\lib\site-packages\ptvsd\pydevd\setup_cython.py" build_ext
--inplace' to build.
```
This is despite `.pyd` files being in their usual locations. Probably this is happening because Cython stuff is loaded dynamically, and by the time pydevd tries to load it, we've already removed the `sys.path` entry.


Discussion:

Resolving patch:
diff --git a/ptvsd/pydevd/_pydevd_bundle/pydevd_frame.py b/ptvsd/pydevd/_pydevd_bundle/pydevd_frame.py
--- a/ptvsd/pydevd/_pydevd_bundle/pydevd_frame.py
+++ b/ptvsd/pydevd/_pydevd_bundle/pydevd_frame.py
@@ -50,7 +50,7 @@ def handle_breakpoint_condition(py_db, info, breakpoint, new_frame):
         sys.stderr.write(msg)
         traceback.print_exc()
         if not py_db.suspend_on_breakpoint_exception:
-            return default_return_value
+            return False
         else:
             stop = True
             try:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -6,14 +6,18 @@
 
 import os
 import os.path
+import subprocess
 import sys
 
 from setuptools import setup, Extension
 
+if not os.getenv('SKIP_CYTHON_BUILD'):
+    print('Compiling extension modules (set SKIP_CYTHON_BUILD=1 to omit)')
+    subprocess.check_call(
+        [sys.executable, 'ptvsd/pydevd/setup_cython.py', 'build_ext', '-i'])
 
 ROOT = os.path.dirname(os.path.abspath(__file__))
 
-
 # Add pydevd files as data files for this package. They are not treated
 # as a package of their own, because we don't actually want to provide
 # pydevd - just use our own copy internally.
@@ -32,22 +36,13 @@ def get_pydevd_package_data():
             files[:] = [f
                         for f in files
                         if f.endswith('.py') and 'pydev' in f]
+        dirs[:] = [d for d in dirs if d != '__pycache__']
         for f in files:
             yield os.path.join(root[len(ptvsd_prefix) + 1:], f)
 
-
-cmdclass = {}
-
-if sys.version_info[0] == 2:
-    from setuptools.command.build_ext import build_ext
-
-    class build_optional_ext(build_ext):
-        def build_extension(self, ext):
-            try:
-                super(build_optional_ext, self).build_extension(ext)
-            except Exception:
-                pass
-    cmdclass = {'build_ext': build_optional_ext}
+PACKAGE_DATA = {
+    'ptvsd': list(get_pydevd_package_data()) + ['ThirdPartyNotices.txt']
+}
 
 setup(
     name='ptvsd',
@@ -65,15 +60,5 @@ def build_extension(self, ext):
         'License :: OSI Approved :: MIT License',
     ],
     packages=['ptvsd'],
-    package_data={
-        'ptvsd': list(get_pydevd_package_data()) + [
-            'ThirdPartyNotices.txt',
-         ],
-    },
-    ext_modules=[
-        Extension('ptvsd.pydevd._pydevd_bundle.pydevd_cython',
-                  ['ptvsd/pydevd/_pydevd_bundle/pydevd_cython.c'],
-                  optional=True),
-    ],
-    cmdclass=cmdclass,
+    package_data=PACKAGE_DATA,
 )


Test patch:
Repository: microsoft/ptvsd

Issue:
Running program to completion prints error message before exiting
* Debug program without any breakpoints
* Python program contains simple print statements
* When run to completion debugger prints the following:
```
Error in atexit._run_exitfuncs:
TypeError: handler() missing 2 required positional arguments: 'proc' and 'server_thread'
```




Discussion:
@ericsnowcurrently 
I don't think we need the arguments for `handler` function as these values have been captured in the current scope.
See here: https://github.com/Microsoft/ptvsd/blob/master/ptvsd/wrapper.py#L1353

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1350,7 +1350,7 @@ def _start(client, server, killonclose=True, addhandlers=True):
 
 
 def _add_atexit_handler(proc, server_thread):
-    def handler(proc, server_thread):
+    def handler():
         proc.close()
         if server_thread.is_alive():
             server_thread.join(WAIT_FOR_THREAD_FINISH_TIMEOUT)


Test patch:
Repository: microsoft/ptvsd

Issue:
Running Python code to completion randomly fails with error 
**Very difficult to replicate**

Python Code:
```
import sys
sys.stdout.write("OUT")
sys.stderr.write("EXs")
```

Traceoutput:
```
OUTEXError in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 1334, in <lambda>
    atexit.register(lambda: exit_handler(proc, server_thread))
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 1293, in exit_handler
    proc.close()
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 535, in close
    self.socket.shutdown(socket.SHUT_RDWR)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 57] Socket is not connected
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 1334, in <lambda>
    atexit.register(lambda: exit_handler(proc, server_thread))
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 1293, in exit_handler
    proc.close()
  File "/Users/donjayamanne/.vscode/extensions/ms-python.python-2018.3.0-alpha/pythonFiles/experimental/ptvsd/ptvsd/wrapper.py", line 535, in close
    self.socket.shutdown(socket.SHUT_RDWR)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 57] Socket is not connected
```


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -555,8 +555,11 @@ def close(self):
         self.event_loop_thread.join(WAIT_FOR_THREAD_FINISH_TIMEOUT)
 
         if self.socket:
-            self.socket.shutdown(socket.SHUT_RDWR)
-            self.socket.close()
+            try:
+                self.socket.shutdown(socket.SHUT_RDWR)
+                self.socket.close()
+            except Exception:
+                pass
 
     def pydevd_notify(self, cmd_id, args):
         # TODO: docstring


Test patch:
Repository: microsoft/ptvsd

Issue:
Debugging of modules using -m is broken
Used to be able to debug Flask & other code using the `-m` flag.



Discussion:

Resolving patch:
diff --git a/ptvsd/debugger.py b/ptvsd/debugger.py
--- a/ptvsd/debugger.py
+++ b/ptvsd/debugger.py
@@ -27,7 +27,7 @@ def debug(filename, port_num, debug_id, debug_options, run_as):
 def _run_module(address, modname):
     filename = modname + ':'
     argv = _run_argv(address, filename)
-    argv.append('--module')
+    argv.insert(argv.index('--file'), '--module')
     _run(argv)
 
 


Test patch:
Repository: microsoft/ptvsd

Issue:
Django breakpoints do not work in VSC on Windows
The problem is the setting `FIX_FILE_PATH_CASE` hasn't been added to known list of settings in `_parse_debug_options`


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -879,6 +879,7 @@ def _parse_debug_options(self, debug_options):
             'WEB_BROWSER_URL': unquote,
             'DJANGO_DEBUG': bool,
             'FLASK_DEBUG': bool,
+            'FIX_FILE_PATH_CASE': bool
         }
 
         options = {}


Test patch:
Repository: microsoft/ptvsd

Issue:
Handle debug options for attach in VSC



Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -906,6 +906,9 @@ def on_disconnect(self, request, args):
     def on_attach(self, request, args):
         # TODO: docstring
         self.start_reason = 'attach'
+        options = self.build_debug_options(args.get('debugOptions', []))
+        self.debug_options = self._parse_debug_options(
+            args.get('options', options))
         self.send_response(request)
 
     @async_handler


Test patch:
Repository: microsoft/ptvsd

Issue:
Unable to launch the debugger
Getting the following error in master when debugging in VSC:
```
Could not connect to None: 60857
Traceback (most recent call last):
  File "/Users/donjayamanne/Desktop/Development/vscode/ptvsd/ptvsd/pydevd/pydevd.py", line 1620, in main
    debugger.connect(host, port)
  File "/Users/donjayamanne/Desktop/Development/vscode/ptvsd/ptvsd/pydevd/pydevd.py", line 326, in connect
    s = start_server(port)
  File "/Users/donjayamanne/Desktop/Development/vscode/ptvsd/ptvsd/wrapper.py", line 1766, in start_server
    server = _create_server(port)
  File "/Users/donjayamanne/Desktop/Development/vscode/ptvsd/ptvsd/wrapper.py", line 1701, in _create_server
    server.bind(('127.0.0.1', port))
OSError: [Errno 48] Address already in u
```


Discussion:
This would indicate the live tests we have today are not sufficient or not mimicking VSC.
@karthiknadig Please could you test the latest master branch as well.
@ericsnowcurrently 

The problem is the `--client` arg is not appended into the list when it should be.

```python
def _run_argv(address, filename, *extra):
    """Convert the given values to an argv that pydevd.main() supports."""
    if '--' in extra:
        pydevd = list(extra[:extra.index('--')])
        extra = list(extra[len(pydevd) + 1:])
    else:
        pydevd = []
        extra = list(extra)

    host, port=address
    print(host)
    #if host is None:
    #    host = '127.0.0.1'
    argv = [
        sys.argv[0],
        '--port', str(port),
    ]
    if host is not None:
        argv.extend([
            '--client', host,
        ])
```

Today I'm launching PTVSD by invoking the function `debug` in `debugger.py`:
```typescript
vspd.debug(filename, port_num, debug_id, debug_options, run_as)
```
@ericsnowcurrently 
When possible, please do look at this issue. Should be simple. I'd fix it, but I'm not sure what the right approach is, as you have commented out the code that initializes the host to `127.0.0.1`.

Oh yes, this PR is quite crucial for VSC, as it breaks all of our PRs (we're pulling the master branch of PTVSD in VSC CI tests , i.e. none of our CI tests pass as a result of this 😄)
FWIW, I expect that the culprit is PR #266.

Resolving patch:
diff --git a/ptvsd/debugger.py b/ptvsd/debugger.py
--- a/ptvsd/debugger.py
+++ b/ptvsd/debugger.py
@@ -14,7 +14,7 @@
 
 def debug(filename, port_num, debug_id, debug_options, run_as, **kwargs):
     # TODO: docstring
-    address = (None, port_num)
+    address = ('localhost', port_num)
     if run_as == 'module':
         run_module(address, filename, **kwargs)
     else:


Test patch:
Repository: microsoft/ptvsd

Issue:
File/project mapping for remote debugging



Discussion:
Looks like we need this for remoting.
Is this the feature that make it possible to map remote paths to local folders for remote debugging?

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -10,6 +10,7 @@
 import io
 import os
 import platform
+import pydevd_file_utils
 import re
 import signal
 import socket
@@ -930,10 +931,22 @@ def _parse_debug_options(self, debug_options):
             options[key] = DEBUG_OPTIONS_PARSER[key](value)
         return options
 
+    def _initialize_path_maps(self, args):
+        pathMaps = []
+        for pathMapping in args.get('pathMappings', []):
+            localRoot = pathMapping.get('localRoot', '')
+            remoteRoot = pathMapping.get('remoteRoot', '')
+            if (len(localRoot) > 0 and len(remoteRoot) > 0):
+                pathMaps.append((localRoot, remoteRoot))
+
+        if len(pathMaps) > 0:
+            pydevd_file_utils.setup_client_server_paths(pathMaps)
+
     @async_handler
     def on_attach(self, request, args):
         # TODO: docstring
         self.start_reason = 'attach'
+        self._initialize_path_maps(args)
         options = self.build_debug_options(args.get('debugOptions', []))
         self.debug_options = self._parse_debug_options(
             args.get('options', options))


Test patch:
Repository: microsoft/ptvsd

Issue:
VS "Stop Debugging" triggers "Press any key to continue"
It looks like the manner in which VS handles "Stop Debugging" causes ptvsd process to print out the "Press any key to continue" message in its console and wait for input; in the meantime, VS is blocked waiting for debuggee to exit. 


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -635,6 +635,7 @@ def __init__(self, socket, pydevd_notify, pydevd_request,
         self.disconnect_request_event = threading.Event()
         self._exited = False
         self.path_casing = PathUnNormcase()
+        self.start_reason = None
 
     def start(self, threadname):
         # event loop
@@ -687,6 +688,12 @@ def _stop_vsc_message_loop(self):
                 pass
 
     def _wait_options(self):
+        # In attach scenarios, we can't assume that the process is actually
+        # interactive and has a console, so ignore these options.
+        # In launch scenarios, we only want "press any key" to show up when
+        # program terminates by itself, not when user explicitly stops it.
+        if self.disconnect_request or self.start_reason != 'launch':
+            return False, False
         normal = self.debug_options.get('WAIT_ON_NORMAL_EXIT', False)
         abnormal = self.debug_options.get('WAIT_ON_ABNORMAL_EXIT', False)
         return normal, abnormal


Test patch:
Repository: microsoft/ptvsd

Issue:
on_invalid_request should not exit
As the comment there suggests, `on_invalid_request` should respond back with
`self.send_response(request, success=False, message='Unknown command')` . It should not exit.


Discussion:
Agreed, I'd say we should add this before the final release.
We can't have the debugger falling over just because there's a new message sent by the debugger.
I will send a PR for this. I need to test a few things from VS side since we make use of the custom messages.

Resolving patch:
diff --git a/ptvsd/ipcjson.py b/ptvsd/ipcjson.py
--- a/ptvsd/ipcjson.py
+++ b/ptvsd/ipcjson.py
@@ -244,7 +244,6 @@ def __init__(self, *args, **kwargs):
         self.__exit = False
         self.__lock = thread.allocate_lock()
         self.__message = []
-        self._exit_on_unknown_command = True
 
     def close(self):
         # TODO: docstring
@@ -357,10 +356,6 @@ def on_event(self, msg):
     def on_invalid_request(self, request, args):
         # TODO: docstring
         self.send_response(request, success=False, message='Unknown command')
-        if self._exit_on_unknown_command:
-            # TODO: Shouldn't we let VSC decide how to handle this
-            # instead of exiting?
-            self.__exit = True
 
     def _receive_message(self, message):
         with self.__lock:


Test patch:
diff --git a/tests/helpers/pydevd/_binder.py b/tests/helpers/pydevd/_binder.py
--- a/tests/helpers/pydevd/_binder.py
+++ b/tests/helpers/pydevd/_binder.py
@@ -26,8 +26,7 @@ def from_connect_func(cls, connect):
         )
         client, server = connect()
         self.start(server)
-        proc = self.set_connection(client)
-        proc._exit_on_unknown_command = False  # TODO: hack alert!
+        self.set_connection(client)
         return self
 
     @property
Repository: microsoft/ptvsd

Issue:
Running program to completion now prints `Terminated` in the console window
* Python program contains `print("Hello world")`
* Debug the above code without any breakpoints
* I.e. let it run to completion

This did not happen in the past.

The output is as follows:
```
pydev debugger: New process is launching (breakpoints won't work in the new process).
pydev debugger: To debug that process please enable 'Attach to subprocess automatically while debugging?' option in the debugger settings.

a
Terminated
```


Discussion:

Resolving patch:
diff --git a/ptvsd/daemon.py b/ptvsd/daemon.py
--- a/ptvsd/daemon.py
+++ b/ptvsd/daemon.py
@@ -40,6 +40,7 @@ def __init__(self, wait_on_exit=_wait_on_exit,
         self.killonclose = killonclose
 
         self._closed = False
+        self._exiting_via_atexit_handler = False
 
         self._pydevd = None
         self._server = None
@@ -124,6 +125,7 @@ def close(self):
 
     def _add_atexit_handler(self):
         def handler():
+            self._exiting_via_atexit_handler = True
             if not self._closed:
                 self.close()
             if self._adapter is not None:
@@ -174,7 +176,7 @@ def _getsockname(self):
     def _handle_vsc_disconnect(self, kill=False):
         if not self._closed:
             self.close()
-        if kill and self.killonclose:
+        if kill and self.killonclose and not self._exiting_via_atexit_handler:
             os.kill(os.getpid(), signal.SIGTERM)
 
     def _handle_vsc_close(self):


Test patch:
Repository: microsoft/ptvsd

Issue:
Path mappings do not work correctly when remote debugging local code
* Start code for remote debugging scenario
* Attach to the code using VSC from the same machine
I.e. remote debugging but from local machine
* Path maps do not work, PTVSD always returns source maps




Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1078,7 +1078,10 @@ def get_source_reference(self, filename):
         try:
             return self.source_map.to_vscode(filename, autogen=False)
         except KeyError:
-            pass
+            # If attaching to a local process (then remote and local are same)
+            for local_prefix, remote_prefix in pydevd_file_utils.PATHS_FROM_ECLIPSE_TO_PYTHON: # noqa
+                if local_prefix == remote_prefix and filename.startswith(local_prefix): # noqa
+                    return 0
 
         server_filename = pydevd_file_utils.norm_file_to_server(filename)
 


Test patch:
Repository: microsoft/ptvsd

Issue:
PTVSD fails to run on windows
```
Traceback (most recent call last):
  File "C:\Users\karth\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\experimental\ptvsd_launcher.py", line 96,
in <module>
    vspd.debug(filename, port_num, debug_id, debug_options, run_as)
  File "c:\git\ptvsd\ptvsd\debugger.py", line 36, in debug
    run(address, filename, *args, **kwargs)
  File "c:\git\ptvsd\ptvsd\__main__.py", line 37, in run_file
    run(argv, addr, **kwargs)
  File "c:\git\ptvsd\ptvsd\__main__.py", line 85, in _run
    daemon = _install(_pydevd, addr, **kwargs)
  File "c:\git\ptvsd\ptvsd\pydevd_hooks.py", line 52, in install
    daemon = Daemon(**kwargs)
  File "c:\git\ptvsd\ptvsd\daemon.py", line 53, in __init__
    self.install_exit_handlers()
  File "c:\git\ptvsd\ptvsd\daemon.py", line 91, in install_exit_handlers
    signal.SIGHUP: [],
AttributeError: module 'signal' has no attribute 'SIGHUP'
```
PTVSD fails to run on windows
```
Traceback (most recent call last):
  File "C:\Users\karth\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\experimental\ptvsd_launcher.py", line 96,
in <module>
    vspd.debug(filename, port_num, debug_id, debug_options, run_as)
  File "c:\git\ptvsd\ptvsd\debugger.py", line 36, in debug
    run(address, filename, *args, **kwargs)
  File "c:\git\ptvsd\ptvsd\__main__.py", line 37, in run_file
    run(argv, addr, **kwargs)
  File "c:\git\ptvsd\ptvsd\__main__.py", line 85, in _run
    daemon = _install(_pydevd, addr, **kwargs)
  File "c:\git\ptvsd\ptvsd\pydevd_hooks.py", line 52, in install
    daemon = Daemon(**kwargs)
  File "c:\git\ptvsd\ptvsd\daemon.py", line 53, in __init__
    self.install_exit_handlers()
  File "c:\git\ptvsd\ptvsd\daemon.py", line 91, in install_exit_handlers
    signal.SIGHUP: [],
AttributeError: module 'signal' has no attribute 'SIGHUP'
```


Discussion:

Resolving patch:
diff --git a/ptvsd/daemon.py b/ptvsd/daemon.py
--- a/ptvsd/daemon.py
+++ b/ptvsd/daemon.py
@@ -168,6 +168,9 @@ def handler():
         self._atexit_handlers.append(handler)
 
     def _add_signal_handlers(self):
+        if platform.system() == 'Windows':
+            return
+
         def handler(signum, frame):
             if not self._closed:
                 self.close()


Test patch:
Repository: microsoft/ptvsd

Issue:
Error in pydev breakpoints
```python
                if len(condition) <= 0 or condition is None or condition == "None":
                    condition = None

                if len(expression) <= 0 or expression is None or expression == "None":
                    expression = None

                if len(hit_condition) <= 0 or hit_condition is None or hit_condition == "None":
                    hit_condition = None
```

We need to check if variables are None before checking the length.


Discussion:

Resolving patch:
diff --git a/ptvsd/pydevd/_pydevd_bundle/pydevd_process_net_command.py b/ptvsd/pydevd/_pydevd_bundle/pydevd_process_net_command.py
--- a/ptvsd/pydevd/_pydevd_bundle/pydevd_process_net_command.py
+++ b/ptvsd/pydevd/_pydevd_bundle/pydevd_process_net_command.py
@@ -293,13 +293,13 @@ def process_net_command(py_db, cmd_id, seq, text):
                     sys.stderr.flush()
 
 
-                if len(condition) <= 0 or condition is None or condition == "None":
+                if condition is not None and (len(condition) <= 0 or condition == "None"):
                     condition = None
 
-                if len(expression) <= 0 or expression is None or expression == "None":
+                if expression is None and (len(expression) <= 0 or expression == "None"):
                     expression = None
 
-                if len(hit_condition) <= 0 or hit_condition is None or hit_condition == "None":
+                if hit_condition is not None and (len(hit_condition) <= 0 or hit_condition == "None"):
                     hit_condition = None
 
                 if type == 'python-line':


Test patch: