@@ -66,7 +66,7 @@ class AutocompleteModes(Enum):
66
66
FUZZY = "fuzzy"
67
67
68
68
@classmethod
69
- def from_string (cls , value : str ) -> Union [Any , None ]:
69
+ def from_string (cls , value : str ) -> Optional [Any ]:
70
70
if value .upper () in cls .__members__ :
71
71
return cls .__members__ [value .upper ()]
72
72
return None
@@ -209,7 +209,7 @@ def method_match_substring(word: str, size: int, text: str) -> bool:
209
209
return text in word
210
210
211
211
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 ]:
213
213
s = r".*%s.*" % ".*" .join (list (text ))
214
214
return re .search (s , word )
215
215
@@ -236,7 +236,7 @@ def __init__(
236
236
@abc .abstractmethod
237
237
def matches (
238
238
self , cursor_offset : int , line : str , ** kwargs : Any
239
- ) -> Union [Set [str ], None ]:
239
+ ) -> Optional [Set [str ]]:
240
240
"""Returns a list of possible matches given a line and cursor, or None
241
241
if this completion type isn't applicable.
242
242
@@ -255,7 +255,7 @@ def matches(
255
255
raise NotImplementedError
256
256
257
257
@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 ]:
259
259
"""Returns a Linepart namedtuple instance or None given cursor and line
260
260
261
261
A Linepart namedtuple contains a start, stop, and word. None is
@@ -299,7 +299,7 @@ def __init__(
299
299
300
300
super ().__init__ (True , mode )
301
301
302
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
302
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
303
303
for completer in self ._completers :
304
304
return_value = completer .locate (cursor_offset , line )
305
305
if return_value is not None :
@@ -311,7 +311,7 @@ def format(self, word: str) -> str:
311
311
312
312
def matches (
313
313
self , cursor_offset : int , line : str , ** kwargs : Any
314
- ) -> Union [ None , Set ]:
314
+ ) -> Optional [ Set ]:
315
315
return_value = None
316
316
all_matches = set ()
317
317
for completer in self ._completers :
@@ -336,10 +336,10 @@ def __init__(
336
336
337
337
def matches (
338
338
self , cursor_offset : int , line : str , ** kwargs : Any
339
- ) -> Union [ None , Set ]:
339
+ ) -> Optional [ Set ]:
340
340
return self .module_gatherer .complete (cursor_offset , line )
341
341
342
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
342
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
343
343
return lineparts .current_word (cursor_offset , line )
344
344
345
345
def format (self , word : str ) -> str :
@@ -355,7 +355,7 @@ def safe_glob(self, pathname: str) -> Iterator[str]:
355
355
356
356
def matches (
357
357
self , cursor_offset : int , line : str , ** kwargs : Any
358
- ) -> Union [ None , Set ]:
358
+ ) -> Optional [ Set ]:
359
359
cs = lineparts .current_string (cursor_offset , line )
360
360
if cs is None :
361
361
return None
@@ -370,7 +370,7 @@ def matches(
370
370
matches .add (filename )
371
371
return matches
372
372
373
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
373
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
374
374
return lineparts .current_string (cursor_offset , line )
375
375
376
376
def format (self , filename : str ) -> str :
@@ -387,7 +387,7 @@ class AttrCompletion(BaseCompletionType):
387
387
388
388
def matches (
389
389
self , cursor_offset : int , line : str , ** kwargs : Any
390
- ) -> Union [ None , Set ]:
390
+ ) -> Optional [ Set ]:
391
391
if "locals_" not in kwargs :
392
392
return None
393
393
locals_ = cast (Dict [str , Any ], kwargs ["locals_" ])
@@ -417,7 +417,7 @@ def matches(
417
417
if few_enough_underscores (r .word .split ("." )[- 1 ], m .split ("." )[- 1 ])
418
418
}
419
419
420
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
420
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
421
421
return lineparts .current_dotted_attribute (cursor_offset , line )
422
422
423
423
def format (self , word : str ) -> str :
@@ -472,7 +472,7 @@ def list_attributes(self, obj: Any) -> List[str]:
472
472
class DictKeyCompletion (BaseCompletionType ):
473
473
def matches (
474
474
self , cursor_offset : int , line : str , ** kwargs : Any
475
- ) -> Union [ None , Set ]:
475
+ ) -> Optional [ Set ]:
476
476
if "locals_" not in kwargs :
477
477
return None
478
478
locals_ = kwargs ["locals_" ]
@@ -495,7 +495,7 @@ def matches(
495
495
else :
496
496
return None
497
497
498
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
498
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
499
499
return lineparts .current_dict_key (cursor_offset , line )
500
500
501
501
def format (self , match : str ) -> str :
@@ -505,7 +505,7 @@ def format(self, match: str) -> str:
505
505
class MagicMethodCompletion (BaseCompletionType ):
506
506
def matches (
507
507
self , cursor_offset : int , line : str , ** kwargs : Any
508
- ) -> Union [ None , Set ]:
508
+ ) -> Optional [ Set ]:
509
509
if "current_block" not in kwargs :
510
510
return None
511
511
current_block = kwargs ["current_block" ]
@@ -517,14 +517,14 @@ def matches(
517
517
return None
518
518
return {name for name in MAGIC_METHODS if name .startswith (r .word )}
519
519
520
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
520
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
521
521
return lineparts .current_method_definition_name (cursor_offset , line )
522
522
523
523
524
524
class GlobalCompletion (BaseCompletionType ):
525
525
def matches (
526
526
self , cursor_offset : int , line : str , ** kwargs : Any
527
- ) -> Union [ None , Set ]:
527
+ ) -> Optional [ Set ]:
528
528
"""Compute matches when text is a simple name.
529
529
Return a list of all keywords, built-in functions and names currently
530
530
defined in self.namespace that match.
@@ -554,14 +554,14 @@ def matches(
554
554
matches .add (_callable_postfix (val , word ))
555
555
return matches if matches else None
556
556
557
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
557
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
558
558
return lineparts .current_single_word (cursor_offset , line )
559
559
560
560
561
561
class ParameterNameCompletion (BaseCompletionType ):
562
562
def matches (
563
563
self , cursor_offset : int , line : str , ** kwargs : Any
564
- ) -> Union [ None , Set ]:
564
+ ) -> Optional [ Set ]:
565
565
if "argspec" not in kwargs :
566
566
return None
567
567
argspec = kwargs ["argspec" ]
@@ -582,18 +582,18 @@ def matches(
582
582
)
583
583
return matches if matches else None
584
584
585
- def locate (self , cursor_offset : int , line : str ) -> Union [LinePart , None ]:
585
+ def locate (self , cursor_offset : int , line : str ) -> Optional [LinePart ]:
586
586
return lineparts .current_word (cursor_offset , line )
587
587
588
588
589
589
class ExpressionAttributeCompletion (AttrCompletion ):
590
590
# 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 ]:
592
592
return lineparts .current_expression_attribute (cursor_offset , line )
593
593
594
594
def matches (
595
595
self , cursor_offset : int , line : str , ** kwargs : Any
596
- ) -> Union [ None , Set ]:
596
+ ) -> Optional [ Set ]:
597
597
if "locals_" not in kwargs :
598
598
return None
599
599
locals_ = kwargs ["locals_" ]
@@ -621,23 +621,21 @@ def matches(
621
621
class MultilineJediCompletion (BaseCompletionType ): # type: ignore [no-redef]
622
622
def matches (
623
623
self , cursor_offset : int , line : str , ** kwargs : Any
624
- ) -> Union [ None , Set ]:
624
+ ) -> Optional [ Set ]:
625
625
return None
626
626
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 ]:
630
628
return None
631
629
632
630
633
631
else :
634
632
635
633
class JediCompletion (BaseCompletionType ):
636
- _orig_start : Union [int , None ]
634
+ _orig_start : Optional [int ]
637
635
638
636
def matches (
639
637
self , cursor_offset : int , line : str , ** kwargs : Any
640
- ) -> Union [ None , Set ]:
638
+ ) -> Optional [ Set ]:
641
639
if "history" not in kwargs :
642
640
return None
643
641
history = kwargs ["history" ]
@@ -687,7 +685,7 @@ def locate(self, cursor_offset: int, line: str) -> LinePart:
687
685
class MultilineJediCompletion (JediCompletion ): # type: ignore [no-redef]
688
686
def matches (
689
687
self , cursor_offset : int , line : str , ** kwargs : Any
690
- ) -> Union [ None , Set ]:
688
+ ) -> Optional [ Set ]:
691
689
if "current_block" not in kwargs or "history" not in kwargs :
692
690
return None
693
691
current_block = kwargs ["current_block" ]
0 commit comments