From e4404f7c4ca46274103cb354d962627943e968b1 Mon Sep 17 00:00:00 2001 From: Gregg Johnson Date: Tue, 28 Jun 2022 19:52:14 -0700 Subject: [PATCH] Return exact page title match first if it exists, falling back to suggestion only if it does not --- wikipedia/wikipedia.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wikipedia/wikipedia.py b/wikipedia/wikipedia.py index 040901a..851d9b2 100644 --- a/wikipedia/wikipedia.py +++ b/wikipedia/wikipedia.py @@ -268,11 +268,7 @@ def page(title=None, pageid=None, auto_suggest=True, redirect=True, preload=Fals if title is not None: if auto_suggest: results, suggestion = search(title, results=1, suggestion=True) - try: - title = suggestion or results[0] - except IndexError: - # if there is no suggestion or search results, the page doesn't exist - raise PageError(title) + title = results[0] if results else suggestion return WikipediaPage(title, redirect=redirect, preload=preload) elif pageid is not None: return WikipediaPage(pageid=pageid, preload=preload)