We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pip 8.0 returns pre-release files for pip list -o without --pre
When running `pip list -o` pip 8.0 is listing pre-release files even though previously it did not. I suspect that this might be because of some of the refactors done by @xavfernandez.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pip/commands/list.py`
Content:
```
1 from __future__ import absolute_import
2 
3 import logging
4 import warnings
5 
6 from pip.basecommand import Command
7 from pip.exceptions import CommandError
8 from pip.index import PackageFinder
9 from pip.utils import (
10     get_installed_distributions, dist_is_editable)
11 from pip.utils.deprecation import RemovedInPip10Warning
12 from pip.cmdoptions import make_option_group, index_group
13 
14 
15 logger = logging.getLogger(__name__)
16 
17 
18 class ListCommand(Command):
19     """
20     List installed packages, including editables.
21 
22     Packages are listed in a case-insensitive sorted order.
23     """
24     name = 'list'
25     usage = """
26       %prog [options]"""
27     summary = 'List installed packages.'
28 
29     def __init__(self, *args, **kw):
30         super(ListCommand, self).__init__(*args, **kw)
31 
32         cmd_opts = self.cmd_opts
33 
34         cmd_opts.add_option(
35             '-o', '--outdated',
36             action='store_true',
37             default=False,
38             help='List outdated packages')
39         cmd_opts.add_option(
40             '-u', '--uptodate',
41             action='store_true',
42             default=False,
43             help='List uptodate packages')
44         cmd_opts.add_option(
45             '-e', '--editable',
46             action='store_true',
47             default=False,
48             help='List editable projects.')
49         cmd_opts.add_option(
50             '-l', '--local',
51             action='store_true',
52             default=False,
53             help=('If in a virtualenv that has global access, do not list '
54                   'globally-installed packages.'),
55         )
56         self.cmd_opts.add_option(
57             '--user',
58             dest='user',
59             action='store_true',
60             default=False,
61             help='Only output packages installed in user-site.')
62 
63         cmd_opts.add_option(
64             '--pre',
65             action='store_true',
66             default=False,
67             help=("Include pre-release and development versions. By default, "
68                   "pip only finds stable versions."),
69         )
70 
71         index_opts = make_option_group(index_group, self.parser)
72 
73         self.parser.insert_option_group(0, index_opts)
74         self.parser.insert_option_group(0, cmd_opts)
75 
76     def _build_package_finder(self, options, index_urls, session):
77         """
78         Create a package finder appropriate to this list command.
79         """
80         return PackageFinder(
81             find_links=options.find_links,
82             index_urls=index_urls,
83             allow_all_prereleases=options.pre,
84             trusted_hosts=options.trusted_hosts,
85             process_dependency_links=options.process_dependency_links,
86             session=session,
87         )
88 
89     def run(self, options, args):
90         if options.allow_external:
91             warnings.warn(
92                 "--allow-external has been deprecated and will be removed in "
93                 "the future. Due to changes in the repository protocol, it no "
94                 "longer has any effect.",
95                 RemovedInPip10Warning,
96             )
97 
98         if options.allow_all_external:
99             warnings.warn(
100                 "--allow-all-external has been deprecated and will be removed "
101                 "in the future. Due to changes in the repository protocol, it "
102                 "no longer has any effect.",
103                 RemovedInPip10Warning,
104             )
105 
106         if options.allow_unverified:
107             warnings.warn(
108                 "--allow-unverified has been deprecated and will be removed "
109                 "in the future. Due to changes in the repository protocol, it "
110                 "no longer has any effect.",
111                 RemovedInPip10Warning,
112             )
113         if options.outdated and options.uptodate:
114             raise CommandError(
115                 "Options --outdated and --uptodate cannot be combined.")
116 
117         if options.outdated:
118             self.run_outdated(options)
119         elif options.uptodate:
120             self.run_uptodate(options)
121         else:
122             self.run_listing(options)
123 
124     def run_outdated(self, options):
125         for dist, latest_version, typ in sorted(
126                 self.find_packages_latest_versions(options),
127                 key=lambda p: p[0].project_name.lower()):
128             if latest_version > dist.parsed_version:
129                 logger.info(
130                     '%s - Latest: %s [%s]',
131                     self.output_package(dist), latest_version, typ,
132                 )
133 
134     def find_packages_latest_versions(self, options):
135         index_urls = [options.index_url] + options.extra_index_urls
136         if options.no_index:
137             logger.info('Ignoring indexes: %s', ','.join(index_urls))
138             index_urls = []
139 
140         dependency_links = []
141         for dist in get_installed_distributions(
142                 local_only=options.local,
143                 user_only=options.user,
144                 editables_only=options.editable):
145             if dist.has_metadata('dependency_links.txt'):
146                 dependency_links.extend(
147                     dist.get_metadata_lines('dependency_links.txt'),
148                 )
149 
150         with self._build_session(options) as session:
151             finder = self._build_package_finder(options, index_urls, session)
152             finder.add_dependency_links(dependency_links)
153 
154             installed_packages = get_installed_distributions(
155                 local_only=options.local,
156                 user_only=options.user,
157                 editables_only=options.editable,
158             )
159             for dist in installed_packages:
160                 typ = 'unknown'
161                 all_candidates = finder.find_all_candidates(dist.key)
162                 if not all_candidates:
163                     continue
164                 best_candidate = max(all_candidates,
165                                      key=finder._candidate_sort_key)
166                 remote_version = best_candidate.version
167                 if best_candidate.location.is_wheel:
168                     typ = 'wheel'
169                 else:
170                     typ = 'sdist'
171                 yield dist, remote_version, typ
172 
173     def run_listing(self, options):
174         installed_packages = get_installed_distributions(
175             local_only=options.local,
176             user_only=options.user,
177             editables_only=options.editable,
178         )
179         self.output_package_listing(installed_packages)
180 
181     def output_package(self, dist):
182         if dist_is_editable(dist):
183             return '%s (%s, %s)' % (
184                 dist.project_name,
185                 dist.version,
186                 dist.location,
187             )
188         else:
189             return '%s (%s)' % (dist.project_name, dist.version)
190 
191     def output_package_listing(self, installed_packages):
192         installed_packages = sorted(
193             installed_packages,
194             key=lambda dist: dist.project_name.lower(),
195         )
196         for dist in installed_packages:
197             logger.info(self.output_package(dist))
198 
199     def run_uptodate(self, options):
200         uptodate = []
201         for dist, version, typ in self.find_packages_latest_versions(options):
202             if dist.parsed_version == version:
203                 uptodate.append(dist)
204         self.output_package_listing(uptodate)
205
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pip/commands/list.py b/pip/commands/list.py
--- a/pip/commands/list.py
+++ b/pip/commands/list.py
@@ -159,6 +159,11 @@
             for dist in installed_packages:
                 typ = 'unknown'
                 all_candidates = finder.find_all_candidates(dist.key)
+                if not options.pre:
+                    # Remove prereleases
+                    all_candidates = [candidate for candidate in all_candidates
+                                      if not candidate.version.is_prerelease]
+
                 if not all_candidates:
                     continue
                 best_candidate = max(all_candidates,

{"golden_diff": "diff --git a/pip/commands/list.py b/pip/commands/list.py\n--- a/pip/commands/list.py\n+++ b/pip/commands/list.py\n@@ -159,6 +159,11 @@\n             for dist in installed_packages:\n                 typ = 'unknown'\n                 all_candidates = finder.find_all_candidates(dist.key)\n+                if not options.pre:\n+                    # Remove prereleases\n+                    all_candidates = [candidate for candidate in all_candidates\n+                                      if not candidate.version.is_prerelease]\n+\n                 if not all_candidates:\n                     continue\n                 best_candidate = max(all_candidates,\n", "issue": "pip 8.0 returns pre-release files for pip list -o without --pre\nWhen running `pip list -o` pip 8.0 is listing pre-release files even though previously it did not. I suspect that this might be because of some of the refactors done by @xavfernandez.\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport logging\nimport warnings\n\nfrom pip.basecommand import Command\nfrom pip.exceptions import CommandError\nfrom pip.index import PackageFinder\nfrom pip.utils import (\n    get_installed_distributions, dist_is_editable)\nfrom pip.utils.deprecation import RemovedInPip10Warning\nfrom pip.cmdoptions import make_option_group, index_group\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass ListCommand(Command):\n    \"\"\"\n    List installed packages, including editables.\n\n    Packages are listed in a case-insensitive sorted order.\n    \"\"\"\n    name = 'list'\n    usage = \"\"\"\n      %prog [options]\"\"\"\n    summary = 'List installed packages.'\n\n    def __init__(self, *args, **kw):\n        super(ListCommand, self).__init__(*args, **kw)\n\n        cmd_opts = self.cmd_opts\n\n        cmd_opts.add_option(\n            '-o', '--outdated',\n            action='store_true',\n            default=False,\n            help='List outdated packages')\n        cmd_opts.add_option(\n            '-u', '--uptodate',\n            action='store_true',\n            default=False,\n            help='List uptodate packages')\n        cmd_opts.add_option(\n            '-e', '--editable',\n            action='store_true',\n            default=False,\n            help='List editable projects.')\n        cmd_opts.add_option(\n            '-l', '--local',\n            action='store_true',\n            default=False,\n            help=('If in a virtualenv that has global access, do not list '\n                  'globally-installed packages.'),\n        )\n        self.cmd_opts.add_option(\n            '--user',\n            dest='user',\n            action='store_true',\n            default=False,\n            help='Only output packages installed in user-site.')\n\n        cmd_opts.add_option(\n            '--pre',\n            action='store_true',\n            default=False,\n            help=(\"Include pre-release and development versions. By default, \"\n                  \"pip only finds stable versions.\"),\n        )\n\n        index_opts = make_option_group(index_group, self.parser)\n\n        self.parser.insert_option_group(0, index_opts)\n        self.parser.insert_option_group(0, cmd_opts)\n\n    def _build_package_finder(self, options, index_urls, session):\n        \"\"\"\n        Create a package finder appropriate to this list command.\n        \"\"\"\n        return PackageFinder(\n            find_links=options.find_links,\n            index_urls=index_urls,\n            allow_all_prereleases=options.pre,\n            trusted_hosts=options.trusted_hosts,\n            process_dependency_links=options.process_dependency_links,\n            session=session,\n        )\n\n    def run(self, options, args):\n        if options.allow_external:\n            warnings.warn(\n                \"--allow-external has been deprecated and will be removed in \"\n                \"the future. Due to changes in the repository protocol, it no \"\n                \"longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n\n        if options.allow_all_external:\n            warnings.warn(\n                \"--allow-all-external has been deprecated and will be removed \"\n                \"in the future. Due to changes in the repository protocol, it \"\n                \"no longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n\n        if options.allow_unverified:\n            warnings.warn(\n                \"--allow-unverified has been deprecated and will be removed \"\n                \"in the future. Due to changes in the repository protocol, it \"\n                \"no longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n        if options.outdated and options.uptodate:\n            raise CommandError(\n                \"Options --outdated and --uptodate cannot be combined.\")\n\n        if options.outdated:\n            self.run_outdated(options)\n        elif options.uptodate:\n            self.run_uptodate(options)\n        else:\n            self.run_listing(options)\n\n    def run_outdated(self, options):\n        for dist, latest_version, typ in sorted(\n                self.find_packages_latest_versions(options),\n                key=lambda p: p[0].project_name.lower()):\n            if latest_version > dist.parsed_version:\n                logger.info(\n                    '%s - Latest: %s [%s]',\n                    self.output_package(dist), latest_version, typ,\n                )\n\n    def find_packages_latest_versions(self, options):\n        index_urls = [options.index_url] + options.extra_index_urls\n        if options.no_index:\n            logger.info('Ignoring indexes: %s', ','.join(index_urls))\n            index_urls = []\n\n        dependency_links = []\n        for dist in get_installed_distributions(\n                local_only=options.local,\n                user_only=options.user,\n                editables_only=options.editable):\n            if dist.has_metadata('dependency_links.txt'):\n                dependency_links.extend(\n                    dist.get_metadata_lines('dependency_links.txt'),\n                )\n\n        with self._build_session(options) as session:\n            finder = self._build_package_finder(options, index_urls, session)\n            finder.add_dependency_links(dependency_links)\n\n            installed_packages = get_installed_distributions(\n                local_only=options.local,\n                user_only=options.user,\n                editables_only=options.editable,\n            )\n            for dist in installed_packages:\n                typ = 'unknown'\n                all_candidates = finder.find_all_candidates(dist.key)\n                if not all_candidates:\n                    continue\n                best_candidate = max(all_candidates,\n                                     key=finder._candidate_sort_key)\n                remote_version = best_candidate.version\n                if best_candidate.location.is_wheel:\n                    typ = 'wheel'\n                else:\n                    typ = 'sdist'\n                yield dist, remote_version, typ\n\n    def run_listing(self, options):\n        installed_packages = get_installed_distributions(\n            local_only=options.local,\n            user_only=options.user,\n            editables_only=options.editable,\n        )\n        self.output_package_listing(installed_packages)\n\n    def output_package(self, dist):\n        if dist_is_editable(dist):\n            return '%s (%s, %s)' % (\n                dist.project_name,\n                dist.version,\n                dist.location,\n            )\n        else:\n            return '%s (%s)' % (dist.project_name, dist.version)\n\n    def output_package_listing(self, installed_packages):\n        installed_packages = sorted(\n            installed_packages,\n            key=lambda dist: dist.project_name.lower(),\n        )\n        for dist in installed_packages:\n            logger.info(self.output_package(dist))\n\n    def run_uptodate(self, options):\n        uptodate = []\n        for dist, version, typ in self.find_packages_latest_versions(options):\n            if dist.parsed_version == version:\n                uptodate.append(dist)\n        self.output_package_listing(uptodate)\n", "path": "pip/commands/list.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nimport logging\nimport warnings\n\nfrom pip.basecommand import Command\nfrom pip.exceptions import CommandError\nfrom pip.index import PackageFinder\nfrom pip.utils import (\n    get_installed_distributions, dist_is_editable)\nfrom pip.utils.deprecation import RemovedInPip10Warning\nfrom pip.cmdoptions import make_option_group, index_group\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass ListCommand(Command):\n    \"\"\"\n    List installed packages, including editables.\n\n    Packages are listed in a case-insensitive sorted order.\n    \"\"\"\n    name = 'list'\n    usage = \"\"\"\n      %prog [options]\"\"\"\n    summary = 'List installed packages.'\n\n    def __init__(self, *args, **kw):\n        super(ListCommand, self).__init__(*args, **kw)\n\n        cmd_opts = self.cmd_opts\n\n        cmd_opts.add_option(\n            '-o', '--outdated',\n            action='store_true',\n            default=False,\n            help='List outdated packages')\n        cmd_opts.add_option(\n            '-u', '--uptodate',\n            action='store_true',\n            default=False,\n            help='List uptodate packages')\n        cmd_opts.add_option(\n            '-e', '--editable',\n            action='store_true',\n            default=False,\n            help='List editable projects.')\n        cmd_opts.add_option(\n            '-l', '--local',\n            action='store_true',\n            default=False,\n            help=('If in a virtualenv that has global access, do not list '\n                  'globally-installed packages.'),\n        )\n        self.cmd_opts.add_option(\n            '--user',\n            dest='user',\n            action='store_true',\n            default=False,\n            help='Only output packages installed in user-site.')\n\n        cmd_opts.add_option(\n            '--pre',\n            action='store_true',\n            default=False,\n            help=(\"Include pre-release and development versions. By default, \"\n                  \"pip only finds stable versions.\"),\n        )\n\n        index_opts = make_option_group(index_group, self.parser)\n\n        self.parser.insert_option_group(0, index_opts)\n        self.parser.insert_option_group(0, cmd_opts)\n\n    def _build_package_finder(self, options, index_urls, session):\n        \"\"\"\n        Create a package finder appropriate to this list command.\n        \"\"\"\n        return PackageFinder(\n            find_links=options.find_links,\n            index_urls=index_urls,\n            allow_all_prereleases=options.pre,\n            trusted_hosts=options.trusted_hosts,\n            process_dependency_links=options.process_dependency_links,\n            session=session,\n        )\n\n    def run(self, options, args):\n        if options.allow_external:\n            warnings.warn(\n                \"--allow-external has been deprecated and will be removed in \"\n                \"the future. Due to changes in the repository protocol, it no \"\n                \"longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n\n        if options.allow_all_external:\n            warnings.warn(\n                \"--allow-all-external has been deprecated and will be removed \"\n                \"in the future. Due to changes in the repository protocol, it \"\n                \"no longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n\n        if options.allow_unverified:\n            warnings.warn(\n                \"--allow-unverified has been deprecated and will be removed \"\n                \"in the future. Due to changes in the repository protocol, it \"\n                \"no longer has any effect.\",\n                RemovedInPip10Warning,\n            )\n        if options.outdated and options.uptodate:\n            raise CommandError(\n                \"Options --outdated and --uptodate cannot be combined.\")\n\n        if options.outdated:\n            self.run_outdated(options)\n        elif options.uptodate:\n            self.run_uptodate(options)\n        else:\n            self.run_listing(options)\n\n    def run_outdated(self, options):\n        for dist, latest_version, typ in sorted(\n                self.find_packages_latest_versions(options),\n                key=lambda p: p[0].project_name.lower()):\n            if latest_version > dist.parsed_version:\n                logger.info(\n                    '%s - Latest: %s [%s]',\n                    self.output_package(dist), latest_version, typ,\n                )\n\n    def find_packages_latest_versions(self, options):\n        index_urls = [options.index_url] + options.extra_index_urls\n        if options.no_index:\n            logger.info('Ignoring indexes: %s', ','.join(index_urls))\n            index_urls = []\n\n        dependency_links = []\n        for dist in get_installed_distributions(\n                local_only=options.local,\n                user_only=options.user,\n                editables_only=options.editable):\n            if dist.has_metadata('dependency_links.txt'):\n                dependency_links.extend(\n                    dist.get_metadata_lines('dependency_links.txt'),\n                )\n\n        with self._build_session(options) as session:\n            finder = self._build_package_finder(options, index_urls, session)\n            finder.add_dependency_links(dependency_links)\n\n            installed_packages = get_installed_distributions(\n                local_only=options.local,\n                user_only=options.user,\n                editables_only=options.editable,\n            )\n            for dist in installed_packages:\n                typ = 'unknown'\n                all_candidates = finder.find_all_candidates(dist.key)\n                if not options.pre:\n                    # Remove prereleases\n                    all_candidates = [candidate for candidate in all_candidates\n                                      if not candidate.version.is_prerelease]\n\n                if not all_candidates:\n                    continue\n                best_candidate = max(all_candidates,\n                                     key=finder._candidate_sort_key)\n                remote_version = best_candidate.version\n                if best_candidate.location.is_wheel:\n                    typ = 'wheel'\n                else:\n                    typ = 'sdist'\n                yield dist, remote_version, typ\n\n    def run_listing(self, options):\n        installed_packages = get_installed_distributions(\n            local_only=options.local,\n            user_only=options.user,\n            editables_only=options.editable,\n        )\n        self.output_package_listing(installed_packages)\n\n    def output_package(self, dist):\n        if dist_is_editable(dist):\n            return '%s (%s, %s)' % (\n                dist.project_name,\n                dist.version,\n                dist.location,\n            )\n        else:\n            return '%s (%s)' % (dist.project_name, dist.version)\n\n    def output_package_listing(self, installed_packages):\n        installed_packages = sorted(\n            installed_packages,\n            key=lambda dist: dist.project_name.lower(),\n        )\n        for dist in installed_packages:\n            logger.info(self.output_package(dist))\n\n    def run_uptodate(self, options):\n        uptodate = []\n        for dist, version, typ in self.find_packages_latest_versions(options):\n            if dist.parsed_version == version:\n                uptodate.append(dist)\n        self.output_package_listing(uptodate)\n", "path": "pip/commands/list.py"}]}