Skip to content

Commit 987ccb2

Browse files
committed
Prefer str.partition over str.split(..., maxsize=1)
1 parent 03c2373 commit 987ccb2

File tree

28 files changed

+53
-51
lines changed

28 files changed

+53
-51
lines changed

sphinx/_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _load_subcommand_descriptions() -> Iterator[tuple[str, str]]:
6464
# log an error here, but don't fail the full enumeration
6565
print(f'Failed to load the description for {command}', file=sys.stderr)
6666
else:
67-
yield command, description.split('\n\n', 1)[0]
67+
yield command, description.partition('\n\n')[0]
6868

6969

7070
class _RootArgumentParser(argparse.ArgumentParser):

sphinx/builders/latex/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ def write_message_catalog(self) -> None:
513513
formats = self.config.numfig_format
514514
context = {
515515
'addtocaptions': r'\@iden',
516-
'figurename': formats.get('figure', '').split('%s', 1),
517-
'tablename': formats.get('table', '').split('%s', 1),
518-
'literalblockname': formats.get('code-block', '').split('%s', 1),
516+
'figurename': formats.get('figure', '').split('%s', maxsplit=1),
517+
'tablename': formats.get('table', '').split('%s', maxsplit=1),
518+
'literalblockname': formats.get('code-block', '').split('%s', maxsplit=1),
519519
}
520520

521521
if self.context['babel'] or self.context['polyglossia']:

sphinx/cmd/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ def _parse_confoverrides(
371371
val: Any
372372
for val in define:
373373
try:
374-
key, val = val.split('=', 1)
374+
key, _, val = val.partition('=')
375375
except ValueError:
376376
parser.error(__('-D option argument must be in the form name=value'))
377377
confoverrides[key] = val
378378

379379
for val in htmldefine:
380380
try:
381-
key, val = val.split('=')
381+
key, _, val = val.partition('=')
382382
except ValueError:
383383
parser.error(__('-A option argument must be in the form name=value'))
384384
with contextlib.suppress(ValueError):

sphinx/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def __init__(
320320

321321
for name in list(self._overrides.keys()):
322322
if '.' in name:
323-
real_name, key = name.split('.', 1)
323+
real_name, _, key = name.partition('.')
324324
raw_config.setdefault(real_name, {})[key] = self._overrides.pop(name)
325325

326326
self.setup: _ExtensionSetupFunc | None = raw_config.get('setup')

sphinx/directives/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def run(self) -> list[Node]:
201201
* parse the content and handle doc fields in it
202202
"""
203203
if ':' in self.name:
204-
self.domain, self.objtype = self.name.split(':', 1)
204+
self.domain, _, self.objtype = self.name.partition(':')
205205
else:
206206
self.domain, self.objtype = '', self.name
207207
self.indexnode = addnodes.index(entries=[])

sphinx/domains/c/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def run(self) -> list[Node]:
668668
The code is therefore based on the ObjectDescription version.
669669
"""
670670
if ':' in self.name:
671-
self.domain, self.objtype = self.name.split(':', 1)
671+
self.domain, _, self.objtype = self.name.partition(':')
672672
else:
673673
self.domain, self.objtype = '', self.name
674674

sphinx/domains/cpp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def run(self) -> list[Node]:
812812
The code is therefore based on the ObjectDescription version.
813813
"""
814814
if ':' in self.name:
815-
self.domain, self.objtype = self.name.split(':', 1)
815+
self.domain, _, self.objtype = self.name.partition(':')
816816
else:
817817
self.domain, self.objtype = '', self.name
818818

sphinx/domains/javascript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def handle_signature(self, sig: str, signode: desc_signature) -> tuple[str, str]
7070
"""
7171
sig = sig.strip()
7272
if '(' in sig and sig[-1:] == ')':
73-
member, arglist = sig.split('(', 1)
73+
member, _, arglist = sig.partition('(')
7474
member = member.strip()
7575
arglist = arglist[:-1].strip()
7676
else:

sphinx/domains/python/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def generate(
671671

672672
entries = content.setdefault(modname[0].lower(), [])
673673

674-
package = modname.split('.', maxsplit=1)[0]
674+
package = modname.partition('.')[0]
675675
if package != modname:
676676
# it's a submodule
677677
if prev_modname == package:

sphinx/domains/python/_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def make_xref(
9393
children = result.children
9494
result.clear()
9595

96-
shortname = target.split('.')[-1]
96+
shortname = target.rpartition('.')[-1]
9797
textnode = innernode('', shortname) # type: ignore[call-arg]
9898
contnodes = [
9999
pending_xref_condition('', '', textnode, condition='resolved'),

0 commit comments

Comments
 (0)