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

Issue:
Xonsh with Python 3.8 acts like an older version of Python
With Python 3.8, Xonsh behaves as if it is using unsorted dictionaries. (Python code borrowed from [Stack Overflow 613218](https://stackoverflow.com/a/613218).)

## Expected Behavior

```
$ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
>>> dict(sorted(x.items(), key=lambda item: item[1]))
{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
>>> 
$ python3 --version
Python 3.8.10
$ 
```

## Current Behavior

The output of the `dict(sorted(...))` below should be sorted by value, i.e. `{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}`.

```
$ xonsh --no-rc
...
$ x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
$ dict(sorted(x.items(), key=lambda item: item[1]))
{0: 0, 1: 2, 2: 1, 3: 4, 4: 3}
$ import sys
$ sys.version_info
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
$ 
$ xonsh --version
xonsh/0.9.13
$ 
```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
Thanks for reporting @bitinerant --  looks like we haven't updated the sorting behavior.

Resolving patch:
diff --git a/xonsh/pretty.py b/xonsh/pretty.py
--- a/xonsh/pretty.py
+++ b/xonsh/pretty.py
@@ -639,13 +639,6 @@ def inner(obj, p, cycle):
             return p.text("{...}")
         p.begin_group(1, start)
         keys = obj.keys()
-        # if dict isn't large enough to be truncated, sort keys before displaying
-        if not (p.max_seq_length and len(obj) >= p.max_seq_length):
-            try:
-                keys = sorted(keys)
-            except Exception:
-                # Sometimes the keys don't sort.
-                pass
         for idx, key in p._enumerate(keys):
             if idx:
                 p.text(",")


Test patch:
diff --git a/tests/test_pretty.py b/tests/test_pretty.py
--- a/tests/test_pretty.py
+++ b/tests/test_pretty.py
@@ -51,6 +51,11 @@
         id="long-dict",
     ),
     (re.compile("1"), "re.compile(r'1', re.UNICODE)"),
+    pytest.param(
+        dict([(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]),
+        "{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}",
+        id="dict-preserve-order",
+    ),
 ]
Repository: xonsh/xonsh

Issue:
update xonsh's pytest plugin
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

We have to update the [pytest-plugin](https://github.com/xonsh/xonsh/blob/main/xonsh/pytest_plugin.py) for the deprecation warning as explained here
https://docs.pytest.org/en/latest/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path


## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/pytest/plugin.py b/xonsh/pytest/plugin.py
--- a/xonsh/pytest/plugin.py
+++ b/xonsh/pytest/plugin.py
@@ -8,6 +8,7 @@
 import sys
 import types
 import typing as tp
+from pathlib import Path
 from traceback import extract_tb, format_list
 from unittest.mock import MagicMock
 
@@ -56,15 +57,15 @@ def _limited_traceback(excinfo):
         return format_list(tb)
 
 
-def pytest_collect_file(parent, path):
-    if path.ext.lower() == ".xsh" and path.basename.startswith("test_"):
-        return XshFile.from_parent(parent, fspath=path)
+def pytest_collect_file(file_path: Path, path, parent):
+    if file_path.suffix.lower() == ".xsh" and file_path.name.startswith("test_"):
+        return XshFile.from_parent(parent, path=file_path)
 
 
 class XshFile(pytest.File):
     def collect(self):
-        sys.path.append(self.fspath.dirname)
-        mod = importlib.import_module(self.fspath.purebasename)
+        sys.path.append(str(self.path.parent))
+        mod = importlib.import_module(self.path.stem)
         sys.path.pop(0)
         tests = [t for t in dir(mod) if t.startswith("test_")]
         for test_name in tests:
@@ -92,7 +93,7 @@ def repr_failure(self, excinfo, **_):
         return "".join(formatted_tb)
 
     def reportinfo(self):
-        return self.fspath, 0, f"xonsh test: {self.name}"
+        return self.path, 0, f"xonsh test: {self.name}"
 
 
 @pytest.fixture


Test patch:
Repository: xonsh/xonsh

Issue:
AttributeError: 'NoneType' object has no attribute 'flush'
## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.12.4               |
| Git SHA          | c3fc7edb             |
| Commit Date      | May 8 17:26:23 2022  |
| Python           | 3.10.4               |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.29               |
| shell type       | prompt_toolkit       |
| history backend  | json                 |
| pygments         | 2.12.0               |
| on posix         | True                 |
| on linux         | True                 |
| distro           | ubuntu               |
| on wsl           | False                |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| xontrib          | []                   |
| RC file 1        | /home/johny/.xonshrc |
+------------------+----------------------+

```

</details>

## Expected Behavior

To exit xonsh correctly.

## Current Behavior

When I exit xonsh it throws an exception. This not happens every time, only in certain conditions.

### Traceback (if applicable)

<details>

```
Exception ignored in atexit callback: <function shutdown at 0x7fe84db6d900>
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 2182, in shutdown
    h.flush()
  File "/usr/lib/python3.10/logging/__init__.py", line 1084, in flush
    self.stream.flush()
  File "/home/johny/.local/pipx/venvs/xonsh/lib/python3.10/site-packages/xonsh/__amalgam__.py", line 16263, in flush
    self.std.flush()
AttributeError: 'NoneType' object has no attribute 'flush'

```

</details>

## Steps to Reproduce

I can reproduce this issue in this way:

- Start xonsh.
- `$ xonfig web`
- Press Ctrl+C to stop server.
- Press Ctrl+D to exit xonsh. The mentioned exception is thrown.

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/base_shell.py b/xonsh/base_shell.py
--- a/xonsh/base_shell.py
+++ b/xonsh/base_shell.py
@@ -191,8 +191,10 @@ def write(self, s):
 
     def flush(self):
         """Flushes both the original stdout and the buffer."""
-        self.std.flush()
-        self.mem.flush()
+        # In certain cases, `std` or `mem` may already be `None` when we're
+        # cleaning up in which case we don't care whether `flush` does anything
+        getattr(getattr(self, "std", lambda: None), "flush", lambda: None)()
+        getattr(getattr(self, "mem", lambda: None), "flush", lambda: None)()
 
     def fileno(self):
         """Tunnel fileno() calls to the std stream."""


Test patch:
Repository: xonsh/xonsh

Issue:
xontrib load: add option to skip not installed xontribs
It will be cool to have an ability to load xontribs without errors about not installed ones.

For example this useful in case when you run xonsh in virtual environment and xonsh tries to run ~/.xonshrc and because of the virtual env has no xontribs xonsh produces errors. Using skip missing xontribs option in xonshrc you can prevent errors. 

## Current Behavior

Show error and return code 1:

```xsh
xontrib load whole_word_jumping xontrib_not_installed
# The following xontribs are enabled but not installed:
#   ['xontrib_not_installed']
# Please make sure that they are installed correctly by checking https://xonsh.github.io/awesome-xontribs/
# Return code 1
```

## Expected Behavior
Add an option `-s` ("(S)ilent" or "(S)kip missing") and return zero code without errors:
```xsh
xontrib load -s whole_word_jumping xontrib_not_installed
# Return code 0
```

## Current workaround

[xontrib-rc-awesome](https://github.com/anki-code/xontrib-rc-awesome/blob/5105050cf2f7318eb8b011f1f7a5897574e6ca05/xontrib/rc_awesome.xsh#L68-L83) has this workaround:

```xsh
from xonsh.xontribs import get_xontribs 
_xontribs_installed = set(get_xontribs().keys()) 
_xontribs_to_load = ('back2dir', 'prompt_bar', 'pipeliner', 'sh',)
xontrib load @(_xontribs_installed.intersection(_xontribs_to_load))
```

## Start point

https://github.com/xonsh/xonsh/blob/3716f3da8636e41482358b61779e274aade8ecf7/xonsh/xontribs.py#L198

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/xontribs.py b/xonsh/xontribs.py
--- a/xonsh/xontribs.py
+++ b/xonsh/xontribs.py
@@ -202,6 +202,7 @@ def xontribs_load(
     ] = (),
     verbose=False,
     full_module=False,
+    suppress_warnings=False,
 ):
     """Load xontribs from a list of names
 
@@ -213,6 +214,8 @@ def xontribs_load(
         verbose output
     full_module : -f, --full
         indicates that the names are fully qualified module paths and not inside ``xontrib`` package
+    suppress_warnings : -s, --suppress-warnings
+        no warnings about missing xontribs and return code 0
     """
     ctx = {} if XSH.ctx is None else XSH.ctx
     res = ExitCode.OK
@@ -225,7 +228,8 @@ def xontribs_load(
         try:
             update_context(name, ctx=ctx, full_module=full_module)
         except XontribNotInstalled:
-            bad_imports.append(name)
+            if not suppress_warnings:
+                bad_imports.append(name)
         except Exception:
             res = ExitCode.INIT_FAILED
             print_exception(f"Failed to load xontrib {name}.")


Test patch:
Repository: xonsh/xonsh

Issue:
cd only respects HOME  from os.environ and not XSH $HOME
## Expected Behavior
Set the $HOME variable, for example /tmp
$HOME = "/tmp"
then call 'cd' by itself, pwd should read /tmp

## Current Behavior
$HOME = "/tmp"
then call "cd", pwd will be equal to os.environ['HOME']

I am on Ubuntu, this happens for the xonsh installed via package and the latest AppImage.

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
I can reproduce:

```xsh
$UPDATE_OS_ENVIRON
# False
$HOME = '/tmp'
cd
pwd
# /home/user  # Expected: /tmp

$UPDATE_OS_ENVIRON = True
$HOME = '/tmp'
cd
pwd
# /tmp  # As expected
```

It looks this question about defaults. Should UPDATE_OS_ENVIRON be True by default or not. What side effects will be if so.

Either way I would expect the common use case in the shell where changing $HOME would also affect cd's default path, like it would in bash.  To be more specific, using cd in the XSH environment should depend on XSH's HOME env var rather than the one from the os module, no matter the value set for $UPDATE_OS_ENVIRON.

Resolving patch:
diff --git a/xonsh/dirstack.py b/xonsh/dirstack.py
--- a/xonsh/dirstack.py
+++ b/xonsh/dirstack.py
@@ -215,7 +215,7 @@ def cd(args, stdin=None):
         del args[0]
 
     if len(args) == 0:
-        d = os.path.expanduser("~")
+        d = env.get("HOME", os.path.expanduser("~"))
     elif len(args) == 1:
         d = os.path.expanduser(args[0])
         if not os.path.isdir(d):


Test patch:
diff --git a/tests/test_dirstack.py b/tests/test_dirstack.py
--- a/tests/test_dirstack.py
+++ b/tests/test_dirstack.py
@@ -101,3 +101,16 @@ def test_cd_autopush(xession, tmpdir):
             dirstack.popd([])
 
     assert old_dir == os.getcwd()
+
+
+def test_cd_home(xession, tmpdir):
+    target = str(tmpdir)
+
+    old_home = xession.env.get("HOME")
+
+    xession.env.update(dict(HOME=target, PWD=os.getcwd(), AUTO_PUSHD=True))
+    dirstack.cd([])
+    assert target == os.getcwd()
+    dirstack.popd([])
+
+    xession.env.update(dict(HOME=old_home))
Repository: xonsh/xonsh

Issue:
history errors when using `sudo`
## Expected Behavior

Open xonsh shell:

```shell
ori@Oris-Mac-mini ~ @ sudo -s
ori@Oris-Mac-mini ~ @ ls # or any other command
```

Open another xonsh shell without getting history errors

## Current Behavior

Open xonsh shell:

```shell
ori@Oris-Mac-mini ~ @ sudo -s
ori@Oris-Mac-mini ~ @ ls # or any other command
```

Open another xonsh shell and getting:

```
ori@Oris-Mac-mini ~ @ Exception in thread Thread-6 (_in_load_thread):
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/prompt_toolkit/history.py", line 188, in _in_load_thread
    for item in self.history.load_history_strings():
  File "/usr/local/lib/python3.10/site-packages/xonsh/ptk_shell/history.py", line 28, in load_history_strings
    for cmd in hist.all_items(newest_first=True):
  File "/usr/local/lib/python3.10/site-packages/xonsh/history/json.py", line 551, in all_items
    json_file = xlj.LazyJSON(f, reopen=False)
  File "/usr/local/lib/python3.10/site-packages/xonsh/lazyjson.py", line 208, in __init__
    self._f = open(f, newline="\n")
PermissionError: [Errno 13] Permission denied: '/Users/ori/.local/share/xonsh/history_json/xonsh-c9eb8d70-1859-4324-955b-48a7b3b1715f.json'
```

This happens because the history files have only root access. I suggest these files will be `chmod`-ed to `777`?

## Steps to Reproduce

- sudo in your existing xonsh session
- execute several commands
- open another shell instance

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/history/json.py b/xonsh/history/json.py
--- a/xonsh/history/json.py
+++ b/xonsh/history/json.py
@@ -426,6 +426,10 @@ def __init__(
                 xlj.ljdump(meta, f, sort_keys=True)
 
             try:
+                sudo_uid = os.environ.get("SUDO_UID")
+                sudo_gid = os.environ.get("SUDO_GID")
+                if None not in (sudo_uid, sudo_gid):
+                    os.chown(self.filename, int(sudo_uid), int(sudo_gid))
                 os.chmod(self.filename, 0o600)
             except Exception:  # pylint: disable=broad-except
                 pass


Test patch:
Repository: xonsh/xonsh

Issue:
General on_pre_spec_run that runs for all commands
I want something like https://xon.sh/events.html#event-categories but for all commands, like just an on_pre_spec_run event. 

> Ahh yeah, you want something like: https://xon.sh/events.html#event-categories but for all commands, like just an on_pre_spec_run event. That would need to be added

https://github.com/xonsh/xonsh/issues/3767#issuecomment-692264398


Discussion:

Resolving patch:
diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py
--- a/xonsh/procs/specs.py
+++ b/xonsh/procs/specs.py
@@ -548,6 +548,9 @@ def _pre_run_event_fire(self, name):
         if events.exists(event_name):
             event = getattr(events, event_name)
             event.fire(spec=self)
+        if events.exists("on_pre_spec_run"):
+            event = events.on_pre_spec_run
+            event.fire(spec=self)
 
     def _post_run_event_fire(self, name, proc):
         events = XSH.builtins.events
@@ -555,6 +558,9 @@ def _post_run_event_fire(self, name, proc):
         if events.exists(event_name):
             event = getattr(events, event_name)
             event.fire(spec=self, proc=proc)
+        if events.exists("on_post_spec_run"):
+            event = events.on_post_spec_run
+            event.fire(spec=self)
 
     #
     # Building methods


Test patch:
Repository: xonsh/xonsh

Issue:
Ugly traceback in exception from xonshrc
Catched this:
```xsh
echo @('$XONSH_SHOW_TRACEBACK = True\n1/0') > /tmp/xonshrc
xonsh --rc /tmp/xonshrc

# xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
# [(Token.Generic.Traceback, 'Traceback (most recent call last):\n'), (Token.Text, '  File '), 
# (Token.Name.Builtin, '"/tmp/xonshrc"'), (Token.Text, ', line '), (Token.Literal.Number, '2'), 
# (Token.Text, ', in '), (Token.Name, '<module>'), (Token.Text.Whitespace, '\n'), (Token.Text.Whitespace, '    '), 
# (Token.Literal.Number.Integer, '1'), (Token.Operator, '/'), (Token.Literal.Number.Integer, '0'), 
# (Token.Text.Whitespace, '\n'), (Token.Generic.Error, '    \nZeroDivisionError'), (Token.Text, ': '), 
# (Token.Name, 'division by zero'), (Token.Text.Whitespace, '\n')]
# error running xonsh run control file '/tmp/xonshrc': division by zero
```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
Hello @dev2718! May be it's related to https://github.com/xonsh/xonsh/pull/4683 ?

Because:
```xsh
echo @('$XONSH_SHOW_TRACEBACK = True\n1/0') > /tmp/xonshrc
$COLOR_RESULTS=0 xonsh --rc /tmp/xonshrc
#xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
#Traceback (most recent call last):
#  File "/tmp/xonshrc", line 2, in <module>
#    1/0
#ZeroDivisionError: division by zero
#error running xonsh run control file '/tmp/xonshrc': division by zero
```

Resolving patch:
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -1109,7 +1109,8 @@ def display_colored_error_message(exc_info, strip_xonsh_error_types=True, limit=
     # color the traceback if available
     _, interactive = _get_manual_env_var("XONSH_INTERACTIVE", 0)
     _, color_results = _get_manual_env_var("COLOR_RESULTS", 0)
-    if not interactive or not color_results or not HAS_PYGMENTS:
+    shell_loaded = hasattr(xsh.shell, "shell")  # do not color traceback in xonshrc file
+    if not interactive or not color_results or not shell_loaded or not HAS_PYGMENTS:
         sys.stderr.write(traceback_str)
         return
 


Test patch:
Repository: xonsh/xonsh

Issue:
xontrib: KeyError: '_func_'

```xsh
xontrib

Exception in {'cls': 'ProcProxy', 'name': None, 'func': <xonsh.xontribs.XontribAlias object at 0x10408fce0>, 'alias': 'xontrib', 'pid': 65857}
Traceback (most recent call last):
  File "/Users/pc/git/xonsh/xonsh/procs/proxies.py", line 842, in wait
    r = self.f(self.args, stdin, stdout, stderr, spec, spec.stack)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pc/git/xonsh/xonsh/cli_utils.py", line 649, in __call__
    result = dispatch(
             ^^^^^^^^^
  File "/Users/pc/git/xonsh/xonsh/cli_utils.py", line 413, in dispatch
    func = ns[_FUNC_NAME]
           ~~^^^^^^^^^^^^
KeyError: '_func_'
```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
@jnoortheen please take a look. I think it's related to latest argparse refactorings.

Resolving patch:
diff --git a/xonsh/cli_utils.py b/xonsh/cli_utils.py
--- a/xonsh/cli_utils.py
+++ b/xonsh/cli_utils.py
@@ -208,10 +208,6 @@ def add_args(
             action.help += " (type: %(type)s)"
 
 
-def empty_help_func(_parser, _stdout):
-    _parser.print_help(file=_stdout)
-
-
 def make_parser(
     func: tp.Union[tp.Callable, str],
     empty_help=False,
@@ -226,7 +222,7 @@ def make_parser(
             kwargs["epilog"] = doc.epilog
     parser = ArgParser(**kwargs)
     if empty_help:
-        parser.set_defaults(**{_FUNC_NAME: empty_help_func})
+        parser.default_command = "--help"
     return parser
 
 
@@ -410,8 +406,9 @@ def dispatch(parser: ap.ArgumentParser, args=None, lenient=False, **ns):
     ns["_parsed"] = parsed
     ns.update(vars(parsed))
 
-    func = ns[_FUNC_NAME]
-    return _dispatch_func(func, ns)
+    if _FUNC_NAME in ns:
+        func = ns[_FUNC_NAME]
+        return _dispatch_func(func, ns)
 
 
 class ArgparseCompleter:
diff --git a/xonsh/xontribs.py b/xonsh/xontribs.py
--- a/xonsh/xontribs.py
+++ b/xonsh/xontribs.py
@@ -399,7 +399,7 @@ def build(self):
         parser.add_command(xontribs_load, prog="load")
         parser.add_command(xontribs_unload, prog="unload")
         parser.add_command(xontribs_reload, prog="reload")
-        parser.add_command(xontribs_list, prog="list")
+        parser.add_command(xontribs_list, prog="list", default=True)
         return parser
 
 


Test patch:
diff --git a/tests/test_cli_utils.py b/tests/test_cli_utils.py
--- a/tests/test_cli_utils.py
+++ b/tests/test_cli_utils.py
@@ -77,3 +77,15 @@ def test_parser_hooking():
         "zsh",
         "bash",
     )
+
+
+def test_parser_default_func(mocker):
+    import xonsh.xontribs as xx
+
+    alias = xx.XontribAlias()
+
+    def func():
+        return True
+
+    mocker.patch.object(xx, "xontribs_list", func)
+    assert alias([]) is True
Repository: xonsh/xonsh

Issue:
which: fix handling of `None` results (#5358)
Close #5358
<!---

Thanks for opening a PR on xonsh!

Please do this:

1. Include a news file with your PR (https://xon.sh/devguide.html#changelog).
2. Add the documentation for your feature into `/docs`.
3. Add the example of usage or before-after behavior.
4. Mention the issue that this PR is addressing e.g. `#1234`.

-->

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
**Warning!** No news item is found for this PR.
If this is an user facing change/feature/fix, please add a news item by copying the format from `news/TEMPLATE.rst`.

Thanks @doronz88 !

Resolving patch:
diff --git a/xonsh/xoreutils/_which.py b/xonsh/xoreutils/_which.py
--- a/xonsh/xoreutils/_which.py
+++ b/xonsh/xoreutils/_which.py
@@ -215,7 +215,8 @@ def whichgen(command, path=None, verbose=0, exts=None):
     if os.sep in command or os.altsep and os.altsep in command:
         if os.path.exists(command):
             match = _cull((command, "explicit path given"), matches, verbose)
-            yield match
+            if match:
+                yield match
     else:
         for i in range(len(path)):
             dirName = path[i]


Test patch: