@@ -66,7 +66,7 @@ class AutocompleteModes(Enum):
6666 FUZZY = "fuzzy"
6767
6868 @classmethod
69- def from_string (cls , value : str ) -> Union [Any , None ]:
69+ def from_string (cls , value : str ) -> Optional [Any ]:
7070 if value .upper () in cls .__members__ :
7171 return cls .__members__ [value .upper ()]
7272 return None
@@ -209,7 +209,7 @@ def method_match_substring(word: str, size: int, text: str) -> bool:
209209 return text in word
210210
211211
212- def method_match_fuzzy (word : str , size : int , text : str ) -> Union [Match , None ]:
212+ def method_match_fuzzy (word : str , size : int , text : str ) -> Optional [Match ]:
213213 s = r".*%s.*" % ".*" .join (list (text ))
214214 return re .search (s , word )
215215
@@ -236,7 +236,7 @@ def __init__(
236236 @abc .abstractmethod
237237 def matches (
238238 self , cursor_offset : int , line : str , ** kwargs : Any
239- ) -> Union [Set [str ], None ]:
239+ ) -> Optional [Set [str ]]:
240240 """Returns a list of possible matches given a line and cursor, or None
241241 if this completion type isn't applicable.
242242
@@ -255,7 +255,7 @@ def matches(
255255 raise NotImplementedError
256256
257257 @abc .abstractmethod
258- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
258+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
259259 """Returns a Linepart namedtuple instance or None given cursor and line
260260
261261 A Linepart namedtuple contains a start, stop, and word. None is
@@ -299,7 +299,7 @@ def __init__(
299299
300300 super ().__init__ (True , mode )
301301
302- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
302+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
303303 for completer in self ._completers :
304304 return_value = completer .locate (cursor_offset , line )
305305 if return_value is not None :
@@ -311,7 +311,7 @@ def format(self, word: str) -> str:
311311
312312 def matches (
313313 self , cursor_offset : int , line : str , ** kwargs : Any
314- ) -> Union [ None , Set ]:
314+ ) -> Optional [ Set ]:
315315 return_value = None
316316 all_matches = set ()
317317 for completer in self ._completers :
@@ -336,10 +336,10 @@ def __init__(
336336
337337 def matches (
338338 self , cursor_offset : int , line : str , ** kwargs : Any
339- ) -> Union [ None , Set ]:
339+ ) -> Optional [ Set ]:
340340 return self .module_gatherer .complete (cursor_offset , line )
341341
342- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
342+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
343343 return lineparts .current_word (cursor_offset , line )
344344
345345 def format (self , word : str ) -> str :
@@ -355,7 +355,7 @@ def safe_glob(self, pathname: str) -> Iterator[str]:
355355
356356 def matches (
357357 self , cursor_offset : int , line : str , ** kwargs : Any
358- ) -> Union [ None , Set ]:
358+ ) -> Optional [ Set ]:
359359 cs = lineparts .current_string (cursor_offset , line )
360360 if cs is None :
361361 return None
@@ -370,7 +370,7 @@ def matches(
370370 matches .add (filename )
371371 return matches
372372
373- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
373+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
374374 return lineparts .current_string (cursor_offset , line )
375375
376376 def format (self , filename : str ) -> str :
@@ -387,7 +387,7 @@ class AttrCompletion(BaseCompletionType):
387387
388388 def matches (
389389 self , cursor_offset : int , line : str , ** kwargs : Any
390- ) -> Union [ None , Set ]:
390+ ) -> Optional [ Set ]:
391391 if "locals_" not in kwargs :
392392 return None
393393 locals_ = cast (Dict [str , Any ], kwargs ["locals_" ])
@@ -417,7 +417,7 @@ def matches(
417417 if few_enough_underscores (r .word .split ("." )[- 1 ], m .split ("." )[- 1 ])
418418 }
419419
420- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
420+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
421421 return lineparts .current_dotted_attribute (cursor_offset , line )
422422
423423 def format (self , word : str ) -> str :
@@ -472,7 +472,7 @@ def list_attributes(self, obj: Any) -> List[str]:
472472class DictKeyCompletion (BaseCompletionType ):
473473 def matches (
474474 self , cursor_offset : int , line : str , ** kwargs : Any
475- ) -> Union [ None , Set ]:
475+ ) -> Optional [ Set ]:
476476 if "locals_" not in kwargs :
477477 return None
478478 locals_ = kwargs ["locals_" ]
@@ -495,7 +495,7 @@ def matches(
495495 else :
496496 return None
497497
498- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
498+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
499499 return lineparts .current_dict_key (cursor_offset , line )
500500
501501 def format (self , match : str ) -> str :
@@ -505,7 +505,7 @@ def format(self, match: str) -> str:
505505class MagicMethodCompletion (BaseCompletionType ):
506506 def matches (
507507 self , cursor_offset : int , line : str , ** kwargs : Any
508- ) -> Union [ None , Set ]:
508+ ) -> Optional [ Set ]:
509509 if "current_block" not in kwargs :
510510 return None
511511 current_block = kwargs ["current_block" ]
@@ -517,14 +517,14 @@ def matches(
517517 return None
518518 return {name for name in MAGIC_METHODS if name .startswith (r .word )}
519519
520- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
520+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
521521 return lineparts .current_method_definition_name (cursor_offset , line )
522522
523523
524524class GlobalCompletion (BaseCompletionType ):
525525 def matches (
526526 self , cursor_offset : int , line : str , ** kwargs : Any
527- ) -> Union [ None , Set ]:
527+ ) -> Optional [ Set ]:
528528 """Compute matches when text is a simple name.
529529 Return a list of all keywords, built-in functions and names currently
530530 defined in self.namespace that match.
@@ -554,14 +554,14 @@ def matches(
554554 matches .add (_callable_postfix (val , word ))
555555 return matches if matches else None
556556
557- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
557+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
558558 return lineparts .current_single_word (cursor_offset , line )
559559
560560
561561class ParameterNameCompletion (BaseCompletionType ):
562562 def matches (
563563 self , cursor_offset : int , line : str , ** kwargs : Any
564- ) -> Union [ None , Set ]:
564+ ) -> Optional [ Set ]:
565565 if "argspec" not in kwargs :
566566 return None
567567 argspec = kwargs ["argspec" ]
@@ -582,18 +582,18 @@ def matches(
582582 )
583583 return matches if matches else None
584584
585- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
585+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
586586 return lineparts .current_word (cursor_offset , line )
587587
588588
589589class ExpressionAttributeCompletion (AttrCompletion ):
590590 # could replace attr completion as a more general case with some work
591- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
591+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
592592 return lineparts .current_expression_attribute (cursor_offset , line )
593593
594594 def matches (
595595 self , cursor_offset : int , line : str , ** kwargs : Any
596- ) -> Union [ None , Set ]:
596+ ) -> Optional [ Set ]:
597597 if "locals_" not in kwargs :
598598 return None
599599 locals_ = kwargs ["locals_" ]
@@ -621,23 +621,21 @@ def matches(
621621 class MultilineJediCompletion (BaseCompletionType ): # type: ignore [no-redef]
622622 def matches (
623623 self , cursor_offset : int , line : str , ** kwargs : Any
624- ) -> Union [ None , Set ]:
624+ ) -> Optional [ Set ]:
625625 return None
626626
627- def locate (
628- self , cursor_offset : int , line : str
629- ) -> Union [LinePart , None ]:
627+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
630628 return None
631629
632630
633631else :
634632
635633 class JediCompletion (BaseCompletionType ):
636- _orig_start : Union [int , None ]
634+ _orig_start : Optional [int ]
637635
638636 def matches (
639637 self , cursor_offset : int , line : str , ** kwargs : Any
640- ) -> Union [ None , Set ]:
638+ ) -> Optional [ Set ]:
641639 if "history" not in kwargs :
642640 return None
643641 history = kwargs ["history" ]
@@ -687,7 +685,7 @@ def locate(self, cursor_offset: int, line: str) -> LinePart:
687685 class MultilineJediCompletion (JediCompletion ): # type: ignore [no-redef]
688686 def matches (
689687 self , cursor_offset : int , line : str , ** kwargs : Any
690- ) -> Union [ None , Set ]:
688+ ) -> Optional [ Set ]:
691689 if "current_block" not in kwargs or "history" not in kwargs :
692690 return None
693691 current_block = kwargs ["current_block" ]
0 commit comments