1+ from __future__ import annotations
2+
13import ast
24import collections .abc as collections_abc
35import inspect
@@ -44,8 +46,8 @@ class PythonCompleter(Completer):
4446
4547 def __init__ (
4648 self ,
47- get_globals : Callable [[], Dict [str , Any ]],
48- get_locals : Callable [[], Dict [str , Any ]],
49+ get_globals : Callable [[], dict [str , Any ]],
50+ get_locals : Callable [[], dict [str , Any ]],
4951 enable_dictionary_completion : Callable [[], bool ],
5052 ) -> None :
5153 super ().__init__ ()
@@ -58,8 +60,8 @@ def __init__(
5860 self ._jedi_completer = JediCompleter (get_globals , get_locals )
5961 self ._dictionary_completer = DictionaryCompleter (get_globals , get_locals )
6062
61- self ._path_completer_cache : Optional [ GrammarCompleter ] = None
62- self ._path_completer_grammar_cache : Optional [ " _CompiledGrammar" ] = None
63+ self ._path_completer_cache : GrammarCompleter | None = None
64+ self ._path_completer_grammar_cache : _CompiledGrammar | None = None
6365
6466 @property
6567 def _path_completer (self ) -> GrammarCompleter :
@@ -74,7 +76,7 @@ def _path_completer(self) -> GrammarCompleter:
7476 return self ._path_completer_cache
7577
7678 @property
77- def _path_completer_grammar (self ) -> " _CompiledGrammar" :
79+ def _path_completer_grammar (self ) -> _CompiledGrammar :
7880 """
7981 Return the grammar for matching paths inside strings inside Python
8082 code.
@@ -85,7 +87,7 @@ def _path_completer_grammar(self) -> "_CompiledGrammar":
8587 self ._path_completer_grammar_cache = self ._create_path_completer_grammar ()
8688 return self ._path_completer_grammar_cache
8789
88- def _create_path_completer_grammar (self ) -> " _CompiledGrammar" :
90+ def _create_path_completer_grammar (self ) -> _CompiledGrammar :
8991 def unwrapper (text : str ) -> str :
9092 return re .sub (r"\\(.)" , r"\1" , text )
9193
@@ -202,8 +204,8 @@ class JediCompleter(Completer):
202204
203205 def __init__ (
204206 self ,
205- get_globals : Callable [[], Dict [str , Any ]],
206- get_locals : Callable [[], Dict [str , Any ]],
207+ get_globals : Callable [[], dict [str , Any ]],
208+ get_locals : Callable [[], dict [str , Any ]],
207209 ) -> None :
208210 super ().__init__ ()
209211
@@ -241,7 +243,7 @@ def get_completions(
241243 # Jedi issue: "KeyError: u'a_lambda'."
242244 # https://github.com/jonathanslenders/ptpython/issues/89
243245 pass
244- except IOError :
246+ except OSError :
245247 # Jedi issue: "IOError: No such file or directory."
246248 # https://github.com/jonathanslenders/ptpython/issues/71
247249 pass
@@ -302,8 +304,8 @@ class DictionaryCompleter(Completer):
302304
303305 def __init__ (
304306 self ,
305- get_globals : Callable [[], Dict [str , Any ]],
306- get_locals : Callable [[], Dict [str , Any ]],
307+ get_globals : Callable [[], dict [str , Any ]],
308+ get_locals : Callable [[], dict [str , Any ]],
307309 ) -> None :
308310 super ().__init__ ()
309311
@@ -385,7 +387,7 @@ def __init__(
385387 re .VERBOSE ,
386388 )
387389
388- def _lookup (self , expression : str , temp_locals : Dict [str , Any ]) -> object :
390+ def _lookup (self , expression : str , temp_locals : dict [str , Any ]) -> object :
389391 """
390392 Do lookup of `object_var` in the context.
391393 `temp_locals` is a dictionary, used for the locals.
@@ -429,7 +431,7 @@ def _do_repr(self, obj: object) -> str:
429431 except BaseException :
430432 raise ReprFailedError
431433
432- def eval_expression (self , document : Document , locals : Dict [str , Any ]) -> object :
434+ def eval_expression (self , document : Document , locals : dict [str , Any ]) -> object :
433435 """
434436 Evaluate
435437 """
@@ -444,7 +446,7 @@ def _get_expression_completions(
444446 self ,
445447 document : Document ,
446448 complete_event : CompleteEvent ,
447- temp_locals : Dict [str , Any ],
449+ temp_locals : dict [str , Any ],
448450 ) -> Iterable [Completion ]:
449451 """
450452 Complete the [ or . operator after an object.
@@ -467,7 +469,7 @@ def _get_item_lookup_completions(
467469 self ,
468470 document : Document ,
469471 complete_event : CompleteEvent ,
470- temp_locals : Dict [str , Any ],
472+ temp_locals : dict [str , Any ],
471473 ) -> Iterable [Completion ]:
472474 """
473475 Complete dictionary keys.
@@ -547,7 +549,7 @@ def _get_attribute_completions(
547549 self ,
548550 document : Document ,
549551 complete_event : CompleteEvent ,
550- temp_locals : Dict [str , Any ],
552+ temp_locals : dict [str , Any ],
551553 ) -> Iterable [Completion ]:
552554 """
553555 Complete attribute names.
@@ -579,13 +581,13 @@ def get_suffix(name: str) -> str:
579581 suffix = get_suffix (name )
580582 yield Completion (name , - len (attr_name ), display = name + suffix )
581583
582- def _sort_attribute_names (self , names : List [str ]) -> List [str ]:
584+ def _sort_attribute_names (self , names : list [str ]) -> list [str ]:
583585 """
584586 Sort attribute names alphabetically, but move the double underscore and
585587 underscore names to the end.
586588 """
587589
588- def sort_key (name : str ) -> Tuple [int , str ]:
590+ def sort_key (name : str ) -> tuple [int , str ]:
589591 if name .startswith ("__" ):
590592 return (2 , name ) # Double underscore comes latest.
591593 if name .startswith ("_" ):
@@ -650,7 +652,7 @@ class ReprFailedError(Exception):
650652
651653
652654def _get_style_for_jedi_completion (
653- jedi_completion : " jedi.api.classes.Completion" ,
655+ jedi_completion : jedi .api .classes .Completion ,
654656) -> str :
655657 """
656658 Return completion style to use for this name.
0 commit comments