From fc57ec912eec9da4c33d8db5416fdb2dada706e7 Mon Sep 17 00:00:00 2001
From: Nikita Kniazev <nok.raven@gmail.com>
Date: Mon, 1 Nov 2021 19:09:58 +0300
Subject: [PATCH 1/5] Handle changed exception type from inspect.getabsfile
 (bpo-44648)

https://bugs.python.org/issue44648 (Python 3.10+)
---
 IPython/core/oinspect.py             |    4 ++--
 IPython/core/tests/test_completer.py |   20 +++++++++++++++-----
 IPython/lib/tests/test_pretty.py     |    1 -
 3 files changed, 17 insertions(+), 8 deletions(-)

--- a/IPython/core/oinspect.py
+++ b/IPython/core/oinspect.py
@@ -224,7 +224,7 @@ def format_argspec(argspec):
 
     DEPRECATED (since 7.10): Do not use; will be removed in future versions.
     """
-    
+
     warnings.warn('`format_argspec` function is deprecated as of IPython 7.10'
                   'and will be removed in future versions.', DeprecationWarning, stacklevel=2)
 
@@ -309,7 +309,7 @@ def find_file(obj) -> str:
     fname = None
     try:
         fname = inspect.getabsfile(obj)
-    except TypeError:
+    except (OSError, TypeError):
         # For an instance, the file that matters is where its class was
         # declared.
         try:
--- a/IPython/core/tests/test_completer.py
+++ b/IPython/core/tests/test_completer.py
@@ -26,6 +26,15 @@ from IPython.core.completer import (
     _deduplicate_completions,
 )
 
+if sys.version_info >= (3, 10):
+    import jedi
+    from pkg_resources import parse_version
+
+    # Requires https://github.com/davidhalter/jedi/pull/1795
+    jedi_issue = parse_version(jedi.__version__) <= parse_version("0.18.0")
+else:
+    jedi_issue = False
+
 # -----------------------------------------------------------------------------
 # Test functions
 # -----------------------------------------------------------------------------
@@ -94,7 +103,7 @@ def test_unicode_range():
         """
     assert len_exp == len_test, message
 
-    # fail if new unicode symbols have been added. 
+    # fail if new unicode symbols have been added.
     assert len_exp <= 138552, message
 
 
@@ -475,6 +484,7 @@ class TestCompleter(unittest.TestCase):
             "encoding" in c.signature
         ), "Signature of function was not found by completer"
 
+    @pytest.mark.xfail(jedi_issue, reason="Known failure on jedi<=0.18.0")
     def test_deduplicate_completions(self):
         """
         Test that completions are correctly deduplicated (even if ranges are not the same)
@@ -500,10 +510,10 @@ class TestCompleter(unittest.TestCase):
 
     def test_greedy_completions(self):
         """
-        Test the capability of the Greedy completer. 
+        Test the capability of the Greedy completer.
 
         Most of the test here does not really show off the greedy completer, for proof
-        each of the text below now pass with Jedi. The greedy completer is capable of more. 
+        each of the text below now pass with Jedi. The greedy completer is capable of more.
 
         See the :any:`test_dict_key_completion_contexts`
 
@@ -611,7 +621,7 @@ class TestCompleter(unittest.TestCase):
 
     def test_limit_to__all__False_ok(self):
         """
-        Limit to all is deprecated, once we remove it this test can go away. 
+        Limit to all is deprecated, once we remove it this test can go away.
         """
         ip = get_ipython()
         c = ip.Completer
@@ -838,7 +848,7 @@ class TestCompleter(unittest.TestCase):
         does return what expected, and does not crash.
         """
         delims = " \t\n`!@#$^&*()=+[{]}\\|;:'\",<>?"
-        
+
         keys = [("foo", "bar"), ("foo", "oof"), ("foo", b"bar"), ('other', 'test')]
 
         # Completion on first key == "foo"
--- a/IPython/lib/tests/test_pretty.py
+++ b/IPython/lib/tests/test_pretty.py
@@ -7,7 +7,6 @@
 
 from collections import Counter, defaultdict, deque, OrderedDict, UserList
 import os
-import pytest
 import types
 import string
 import sys