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

Commitb67e76f

Browse files
committed
Mark some function parameters as positional- or keyword-only
1 parent2430655 commitb67e76f

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

‎userland/core/command.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
classExtendedOptionParser(OptionParserUsersMixin,OptionParser):
9-
def__init__(self,usage:str|tuple[str, ...],**kwargs):
9+
def__init__(self,/,usage:str|tuple[str, ...],**kwargs):
1010
super().__init__(
1111
usage="Usage: "
1212
+f"\n{7*" "}".join(usageifisinstance(usage,tuple)else (usage,)),
@@ -20,7 +20,9 @@ def __init__(self, usage: str | tuple[str, ...], **kwargs):
2020
help="show usage information and exit",
2121
)
2222

23-
defexpect_nargs(self,args:list[str],nargs:int|tuple[int]|tuple[int,int]):
23+
defexpect_nargs(
24+
self,/,args:list[str],nargs:int|tuple[int]|tuple[int,int]
25+
):
2426
ifisinstance(nargs,int):
2527
nargs= (nargs,nargs)
2628

@@ -41,13 +43,15 @@ def expect_nargs(self, args: list[str], nargs: int | tuple[int] | tuple[int, int
4143

4244
defcommand(parser:OptionParser|None=None):
4345
defcreate_utility(
44-
func:Callable[[Values,list[str]],int],
46+
func:Callable[[Values,list[str]],int],/
4547
)->Callable[[],None]:
4648
defexecute_utility():
4749
try:
4850
sys.exit(
49-
func(*parser.parse_args())ifparserelsefunc(Values(),sys.argv[1:])
50-
)
51+
func(*parser.parse_args())
52+
ifparser
53+
elsefunc(Values(),sys.argv[1:])
54+
)
5155
exceptKeyboardInterrupt:
5256
print()
5357
sys.exit(130)

‎userland/core/users.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
classOptionParserUsersMixin(OptionParser):
9-
defparse_owner_spec(self,owner_spec:str)->tuple[int|None,int|None]:
9+
defparse_owner_spec(self,owner_spec:str,/)->tuple[int|None,int|None]:
1010
"""
1111
Accept a string in the form ``[USER][:[GROUP]]`` and return the UID and GID.
1212
Either or both may be None if omitted from the input string.
@@ -26,7 +26,7 @@ def parse_owner_spec(self, owner_spec: str) -> tuple[int | None, int | None]:
2626
returnuid,gid
2727

2828
# pylint: disable=inconsistent-return-statements
29-
defparse_user(self,user:str)->int:
29+
defparse_user(self,user:str,/)->int:
3030
"""
3131
Accept a string representing a username or UID and return the UID.
3232
An appropriate parser error is thrown if obtaining the UID fails.
@@ -40,7 +40,7 @@ def parse_user(self, user: str) -> int:
4040
self.error(f"invalid user:{user}")
4141

4242
# pylint: disable=inconsistent-return-statements
43-
defparse_group(self,group:str)->int:
43+
defparse_group(self,group:str,/)->int:
4444
"""
4545
Accept a string representing a group name or GID and return the GID.
4646
An appropriate parser error is thrown if obtaining the GID fails.
@@ -55,15 +55,15 @@ def parse_group(self, group: str) -> int:
5555

5656

5757
@functools.lru_cache(1000)
58-
defuser_display_name_from_id(uid:int)->str:
58+
defuser_display_name_from_id(uid:int,/)->str:
5959
try:
6060
returnpwd.getpwuid(uid).pw_name
6161
exceptKeyError:
6262
returnstr(uid)
6363

6464

6565
@functools.lru_cache(1000)
66-
defgroup_display_name_from_id(gid:int)->str:
66+
defgroup_display_name_from_id(gid:int,/)->str:
6767
try:
6868
returngrp.getgrgid(gid).gr_name
6969
exceptKeyError:

‎userland/utilities/factor.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SMALL_PRIMES= [3,5,7,11,13,17,19,23,29,31,37,41,43,47]
99

1010

11-
defmiller_rabin(n:int)->bool:
11+
defmiller_rabin(n:int,/)->bool:
1212
"""
1313
A deterministic version of the Miller-Rabin primality test.
1414
"""
@@ -32,7 +32,7 @@ def miller_rabin(n: int) -> bool:
3232
returnTrue
3333

3434

35-
defpollards_rho(n:int,step:int)->int|None:
35+
defpollards_rho(n:int,/,step:int)->int|None:
3636
"""
3737
Pollard's rho algorithm for factorization.
3838
@@ -49,7 +49,7 @@ def pollards_rho(n: int, step: int) -> int | None:
4949

5050

5151
deffactorize(
52-
n:int,cache:dict[int,int]= {p:pforpinSMALL_PRIMES}
52+
n:int,/,*,cache:dict[int,int]= {p:pforpinSMALL_PRIMES}
5353
)->Generator[int]:
5454
"""
5555
Generates prime factors of the integer n.
@@ -70,7 +70,7 @@ def factorize(
7070
else:
7171
foriinrange(1,n-1):
7272
if (factor:=pollards_rho(n,i))andfactor!=n:
73-
yieldfromfactorize(min(n,factor),cache)
73+
yieldfromfactorize(min(n,factor),cache=cache)
7474
break
7575

7676
iffactor==n:
@@ -79,7 +79,7 @@ def factorize(
7979
n//=cast(int,factor)
8080

8181

82-
defformat_exponents(factors:Iterable[int])->str:
82+
defformat_exponents(factors:Iterable[int],/)->str:
8383
processed:list[str]= []
8484

8585
last_factor=0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp