Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3514a7d

Browse files
Use Optional, CR
1 parent4ef513d commit3514a7d

File tree

7 files changed

+36
-52
lines changed

7 files changed

+36
-52
lines changed

‎bpython/autocomplete.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class AutocompleteModes(Enum):
6666
FUZZY="fuzzy"
6767

6868
@classmethod
69-
deffrom_string(cls,value:str)->Union[Any,None]:
69+
deffrom_string(cls,value:str)->Optional[Any]:
7070
ifvalue.upper()incls.__members__:
7171
returncls.__members__[value.upper()]
7272
returnNone
@@ -209,7 +209,7 @@ def method_match_substring(word: str, size: int, text: str) -> bool:
209209
returntextinword
210210

211211

212-
defmethod_match_fuzzy(word:str,size:int,text:str)->Union[Match,None]:
212+
defmethod_match_fuzzy(word:str,size:int,text:str)->Optional[Match]:
213213
s=r".*%s.*"%".*".join(list(text))
214214
returnre.search(s,word)
215215

@@ -236,7 +236,7 @@ def __init__(
236236
@abc.abstractmethod
237237
defmatches(
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
raiseNotImplementedError
256256

257257
@abc.abstractmethod
258-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
258+
deflocate(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-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
302+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
303303
forcompleterinself._completers:
304304
return_value=completer.locate(cursor_offset,line)
305305
ifreturn_valueisnotNone:
@@ -311,7 +311,7 @@ def format(self, word: str) -> str:
311311

312312
defmatches(
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
forcompleterinself._completers:
@@ -336,10 +336,10 @@ def __init__(
336336

337337
defmatches(
338338
self,cursor_offset:int,line:str,**kwargs:Any
339-
)->Union[None,Set]:
339+
)->Optional[Set]:
340340
returnself.module_gatherer.complete(cursor_offset,line)
341341

342-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
342+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
343343
returnlineparts.current_word(cursor_offset,line)
344344

345345
defformat(self,word:str)->str:
@@ -355,7 +355,7 @@ def safe_glob(self, pathname: str) -> Iterator[str]:
355355

356356
defmatches(
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
ifcsisNone:
361361
returnNone
@@ -370,7 +370,7 @@ def matches(
370370
matches.add(filename)
371371
returnmatches
372372

373-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
373+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
374374
returnlineparts.current_string(cursor_offset,line)
375375

376376
defformat(self,filename:str)->str:
@@ -387,7 +387,7 @@ class AttrCompletion(BaseCompletionType):
387387

388388
defmatches(
389389
self,cursor_offset:int,line:str,**kwargs:Any
390-
)->Union[None,Set]:
390+
)->Optional[Set]:
391391
if"locals_"notinkwargs:
392392
returnNone
393393
locals_=cast(Dict[str,Any],kwargs["locals_"])
@@ -417,7 +417,7 @@ def matches(
417417
iffew_enough_underscores(r.word.split(".")[-1],m.split(".")[-1])
418418
}
419419

420-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
420+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
421421
returnlineparts.current_dotted_attribute(cursor_offset,line)
422422

423423
defformat(self,word:str)->str:
@@ -472,7 +472,7 @@ def list_attributes(self, obj: Any) -> List[str]:
472472
classDictKeyCompletion(BaseCompletionType):
473473
defmatches(
474474
self,cursor_offset:int,line:str,**kwargs:Any
475-
)->Union[None,Set]:
475+
)->Optional[Set]:
476476
if"locals_"notinkwargs:
477477
returnNone
478478
locals_=kwargs["locals_"]
@@ -495,7 +495,7 @@ def matches(
495495
else:
496496
returnNone
497497

498-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
498+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
499499
returnlineparts.current_dict_key(cursor_offset,line)
500500

501501
defformat(self,match:str)->str:
@@ -505,7 +505,7 @@ def format(self, match: str) -> str:
505505
classMagicMethodCompletion(BaseCompletionType):
506506
defmatches(
507507
self,cursor_offset:int,line:str,**kwargs:Any
508-
)->Union[None,Set]:
508+
)->Optional[Set]:
509509
if"current_block"notinkwargs:
510510
returnNone
511511
current_block=kwargs["current_block"]
@@ -517,14 +517,14 @@ def matches(
517517
returnNone
518518
return {namefornameinMAGIC_METHODSifname.startswith(r.word)}
519519

520-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
520+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
521521
returnlineparts.current_method_definition_name(cursor_offset,line)
522522

523523

524524
classGlobalCompletion(BaseCompletionType):
525525
defmatches(
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
returnmatchesifmatcheselseNone
556556

557-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
557+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
558558
returnlineparts.current_single_word(cursor_offset,line)
559559

560560

561561
classParameterNameCompletion(BaseCompletionType):
562562
defmatches(
563563
self,cursor_offset:int,line:str,**kwargs:Any
564-
)->Union[None,Set]:
564+
)->Optional[Set]:
565565
if"argspec"notinkwargs:
566566
returnNone
567567
argspec=kwargs["argspec"]
@@ -582,18 +582,18 @@ def matches(
582582
)
583583
returnmatchesifmatcheselseNone
584584

585-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
585+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
586586
returnlineparts.current_word(cursor_offset,line)
587587

588588

589589
classExpressionAttributeCompletion(AttrCompletion):
590590
# could replace attr completion as a more general case with some work
591-
deflocate(self,cursor_offset:int,line:str)->Union[LinePart,None]:
591+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
592592
returnlineparts.current_expression_attribute(cursor_offset,line)
593593

594594
defmatches(
595595
self,cursor_offset:int,line:str,**kwargs:Any
596-
)->Union[None,Set]:
596+
)->Optional[Set]:
597597
if"locals_"notinkwargs:
598598
returnNone
599599
locals_=kwargs["locals_"]
@@ -621,23 +621,21 @@ def matches(
621621
classMultilineJediCompletion(BaseCompletionType):# type: ignore [no-redef]
622622
defmatches(
623623
self,cursor_offset:int,line:str,**kwargs:Any
624-
)->Union[None,Set]:
624+
)->Optional[Set]:
625625
returnNone
626626

627-
deflocate(
628-
self,cursor_offset:int,line:str
629-
)->Union[LinePart,None]:
627+
deflocate(self,cursor_offset:int,line:str)->Optional[LinePart]:
630628
returnNone
631629

632630

633631
else:
634632

635633
classJediCompletion(BaseCompletionType):
636-
_orig_start:Union[int,None]
634+
_orig_start:Optional[int]
637635

638636
defmatches(
639637
self,cursor_offset:int,line:str,**kwargs:Any
640-
)->Union[None,Set]:
638+
)->Optional[Set]:
641639
if"history"notinkwargs:
642640
returnNone
643641
history=kwargs["history"]
@@ -687,7 +685,7 @@ def locate(self, cursor_offset: int, line: str) -> LinePart:
687685
classMultilineJediCompletion(JediCompletion):# type: ignore [no-redef]
688686
defmatches(
689687
self,cursor_offset:int,line:str,**kwargs:Any
690-
)->Union[None,Set]:
688+
)->Optional[Set]:
691689
if"current_block"notinkwargsor"history"notinkwargs:
692690
returnNone
693691
current_block=kwargs["current_block"]

‎bpython/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
importsys
5252
importtime
5353
fromtypingimportIterator,NoReturn,List
54-
fromtyping_extensionsimportLiteral
5554
importunicodedata
5655
fromdataclassesimportdataclass
5756

@@ -145,7 +144,7 @@ def writelines(self, l) -> None:
145144
forsinl:
146145
self.write(s)
147146

148-
defisatty(self)->Literal[True]:
147+
defisatty(self)->bool:
149148
# some third party (amongst them mercurial) depend on this
150149
returnTrue
151150

@@ -176,7 +175,7 @@ def write(self, value) -> NoReturn:
176175
# others, so here's a hack to keep them happy
177176
raiseOSError(errno.EBADF,"sys.stdin is read-only")
178177

179-
defisatty(self)->Literal[True]:
178+
defisatty(self)->bool:
180179
returnTrue
181180

182181
defreadline(self,size=-1):

‎bpython/curtsies.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
classSupportsEventGeneration(Protocol):
4242
defsend(
43-
self,timeout:Union[float,None]
43+
self,timeout:Optional[float]
4444
)->Union[str,curtsies.events.Event,None]:
4545
...
4646

@@ -253,9 +253,7 @@ def curtsies_arguments(parser: argparse._ArgumentGroup) -> None:
253253

254254
def_combined_events(
255255
event_provider:"SupportsEventGeneration",paste_threshold:int
256-
)->Generator[
257-
Union[str,curtsies.events.Event,None],Union[float,None],None
258-
]:
256+
)->Generator[Union[str,curtsies.events.Event,None],Optional[float],None]:
259257
"""Combines consecutive keypress events into paste events."""
260258
timeout=yield"nonsense_event"# so send can be used immediately
261259
queue:collections.deque=collections.deque()

‎bpython/curtsiesfrontend/interaction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
importgreenlet
22
importtime
3-
fromtypingimportOptional
43
fromcurtsiesimportevents
54

65
from ..translationsimport_

‎bpython/curtsiesfrontend/repl.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
fromenumimportEnum
1515

1616
fromtypingimportDict,Any,List,Optional,Tuple,Union,cast
17-
fromtyping_extensionsimportLiteral
1817

1918
importblessings
2019
importcwcwidth
@@ -60,8 +59,6 @@
6059
)
6160
from ..translationsimport_
6261

63-
InputOrOutput=Union[Literal["input"],Literal["output"]]
64-
6562
logger=logging.getLogger(__name__)
6663

6764
INCONSISTENT_HISTORY_MSG="#<---History inconsistent with output shown--->"
@@ -286,7 +283,7 @@ def _process_ps(ps, default_ps: str):
286283
ifnotisinstance(ps,str):
287284
returnps
288285

289-
returnpsifcwcwidth.wcswidth(ps)>=0elsedefault_ps
286+
returnpsifcwcwidth.wcswidth(ps,None)>=0elsedefault_ps
290287

291288

292289
classBaseRepl(Repl):
@@ -387,8 +384,8 @@ def __init__(
387384
# Entries are tuples, where
388385
# - the first element the line (string, not fmtsr)
389386
# - the second element is one of 2 global constants: "input" or "output"
390-
# (useLineTypeTranslator.INPUT orLineTypeTranslator.OUTPUT to avoid typing these strings)
391-
self.all_logical_lines:List[Tuple[str,InputOrOutput]]= []
387+
# (useLineType.INPUT orLineType.OUTPUT to avoid typing these strings)
388+
self.all_logical_lines:List[Tuple[str,LineType]]= []
392389

393390
# formatted version of lines in the buffer kept around so we can
394391
# unhighlight parens using self.reprint_line as called by bpython.Repl
@@ -1629,8 +1626,8 @@ def move_screen_up(current_line_start_row):
16291626
)
16301627
else:# Common case for determining cursor position
16311628
cursor_row,cursor_column=divmod(
1632-
wcswidth(self.current_cursor_line_without_suggestion.s)
1633-
-wcswidth(self.current_line)
1629+
wcswidth(self.current_cursor_line_without_suggestion.s,None)
1630+
-wcswidth(self.current_line,None)
16341631
+wcswidth(self.current_line,max(0,self.cursor_offset))
16351632
+self.number_of_padding_chars_on_current_cursor_line(),
16361633
width,

‎bpython/test/test_inspection.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
importsys
33
importunittest
44

5-
fromtypingimportOptional
6-
fromtypesimportModuleType
7-
85
frombpythonimportinspection
96
frombpython.test.fodderimportencoding_ascii
107
frombpython.test.fodderimportencoding_latin1

‎stubs/cwcwidth.pyi

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp