Skip to content

Commit cac9891

Browse files
committed
Use 68 characters for methods
1 parent 48b617b commit cac9891

File tree

3 files changed

+112
-12
lines changed

3 files changed

+112
-12
lines changed

Tools/clinic/libclinic/_overlong_docstrings.py

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'_abc._abc_subclasscheck',
1010
'_asyncio._swap_current_task',
1111
'_codecs.lookup',
12+
'_collections.deque.rotate',
1213
'_ctypes.byref',
1314
'_curses.assume_default_colors',
1415
'_curses.can_change_color',
@@ -25,6 +26,8 @@
2526
'_curses.start_color',
2627
'_curses.termname',
2728
'_curses.window.enclose',
29+
'_curses.window.is_linetouched',
30+
'_curses.window.putwin',
2831
'_elementtree._set_factories',
2932
'_functools.reduce',
3033
'_gdbm.gdbm.setdefault',
@@ -35,15 +38,18 @@
3538
'_heapq.heappushpop',
3639
'_hmac.HMAC.hexdigest',
3740
'_io._BufferedIOBase.read1',
41+
'_io.FileIO.truncate',
3842
'_lzma._decode_filter_properties',
3943
'_opcode.has_name',
4044
'_remote_debugging.RemoteUnwinder.__init__',
4145
'_remote_debugging.RemoteUnwinder.get_all_awaited_by',
4246
'_remote_debugging.RemoteUnwinder.get_async_stack_trace',
4347
'_socket.if_indextoname',
4448
'_socket.inet_aton',
49+
'_sqlite3.Connection.set_trace_callback',
4550
'_sre.SRE_Match.expand',
4651
'_sre.SRE_Match.groupdict',
52+
'_sre.SRE_Match.span',
4753
'_sre.SRE_Pattern.finditer',
4854
'_sre.SRE_Pattern.search',
4955
'_sre.SRE_Pattern.sub',
@@ -63,13 +69,16 @@
6369
'_tracemalloc.reset_peak',
6470
'_zstd.get_frame_size',
6571
'_zstd.set_parameter_types',
72+
'_zstd.ZstdCompressor.set_pledged_input_size',
6673
'_zstd.ZstdDecompressor.decompress',
6774
'array.array.buffer_info',
6875
'array.array.frombytes',
6976
'array.array.fromfile',
7077
'array.array.tobytes',
7178
'cmath.isfinite',
79+
'datetime.date.strptime',
7280
'datetime.datetime.strptime',
81+
'datetime.time.strptime',
7382
'gc.freeze',
7483
'gc.get_objects',
7584
'itertools.batched.__new__',
@@ -109,18 +118,27 @@
109118
'os.WTERMSIG',
110119
'pwd.getpwall',
111120
'pyexpat.xmlparser.ExternalEntityParserCreate',
121+
'pyexpat.xmlparser.GetInputContext',
112122
'pyexpat.xmlparser.GetReparseDeferralEnabled',
113123
'pyexpat.xmlparser.SetParamEntityParsing',
124+
'pyexpat.xmlparser.SetReparseDeferralEnabled',
114125
'pyexpat.xmlparser.UseForeignDTD',
115126
'readline.get_history_length',
116127
'readline.redisplay',
117128
'readline.set_history_length',
129+
'select.epoll.register',
118130
'signal.set_wakeup_fd',
119131
'unpack', # struct.unpack
120132
'unpack_from', # struct.unpack_from
121133
'termios.tcdrain',
134+
'unicodedata.UCD.bidirectional',
135+
'unicodedata.UCD.category',
122136
'unicodedata.UCD.combining',
123137
'unicodedata.UCD.decomposition',
138+
'unicodedata.UCD.east_asian_width',
139+
'unicodedata.UCD.is_normalized',
140+
'unicodedata.UCD.mirrored',
141+
'zlib.Decompress.decompress',
124142
'zoneinfo.ZoneInfo.dst',
125143
'zoneinfo.ZoneInfo.tzname',
126144
'zoneinfo.ZoneInfo.utcoffset',
@@ -139,35 +157,53 @@
139157
'bytearray.split',
140158
'bytearray.splitlines',
141159
'bytearray.startswith',
160+
'bytearray.translate',
142161
'bytes.count',
143162
'bytes.endswith',
144163
'bytes.find',
145164
'bytes.index',
146165
'bytes.maketrans',
166+
'bytes.removeprefix',
167+
'bytes.removesuffix',
147168
'bytes.rfind',
148169
'bytes.rindex',
170+
'bytes.rsplit',
171+
'bytes.split',
172+
'bytes.splitlines',
149173
'bytes.startswith',
174+
'bytes.translate',
150175
'code.replace',
151176
'complex.conjugate',
177+
'dict.fromkeys',
152178
'dict.pop',
153179
'float.as_integer_ratio',
180+
'frame.f_generator',
154181
'frame.f_trace',
155182
'int.bit_count',
183+
'int.is_integer',
156184
'OrderedDict.fromkeys',
157185
'OrderedDict.pop',
186+
'set.difference',
187+
'set.symmetric_difference',
158188
'set.symmetric_difference_update',
189+
'str.__format__',
159190
'str.count',
160191
'str.endswith',
161192
'str.find',
162193
'str.index',
194+
'str.isalnum',
195+
'str.isascii',
196+
'str.isidentifier',
163197
'str.isprintable',
164198
'str.rfind',
165199
'str.rindex',
166200
'str.rsplit',
167201
'str.split',
202+
'str.splitlines',
168203
'str.startswith',
169204
'str.strip',
170205
'str.swapcase',
206+
'str.translate',
171207
'str.zfill',
172208

173209
# PC/
@@ -179,6 +215,8 @@
179215
'isinstance',
180216
'pow',
181217
'sum',
218+
'_contextvars.Context.get',
219+
'_contextvars.ContextVar.set',
182220
'_imp._override_multi_interp_extensions_check',
183221
'_imp.find_frozen',
184222
'_jit.is_active',
@@ -197,6 +235,10 @@
197235

198236
# Modules/
199237
'_abc.get_cache_token',
238+
'_asyncio.Future.add_done_callback',
239+
'_asyncio.Future.cancel',
240+
'_asyncio.Future.done',
241+
'_asyncio.Future.result',
200242
'_bisect.bisect_left',
201243
'_bisect.bisect_right',
202244
'_bz2.BZ2Decompressor.decompress',
@@ -232,12 +274,14 @@
232274
'_curses.tigetstr',
233275
'_curses.use_env',
234276
'_curses.window.border',
277+
'_curses.window.box',
235278
'_curses.window.derwin',
236279
'_curses.window.getch',
237280
'_curses.window.getkey',
238281
'_curses.window.inch',
239282
'_curses.window.insch',
240283
'_curses.window.insnstr',
284+
'_curses.window.insstr',
241285
'_curses.window.is_linetouched',
242286
'_curses.window.noutrefresh',
243287
'_curses.window.overlay',
@@ -248,44 +292,65 @@
248292
'_curses.window.touchline',
249293
'_curses_panel.panel.hide',
250294
'_curses_panel.update_panels',
295+
'_dbm.dbm.setdefault',
251296
'_functools.reduce',
297+
'_gdbm.gdbm.firstkey',
298+
'_gdbm.gdbm.nextkey',
299+
'_gdbm.gdbm.reorganize',
252300
'_hashlib.get_fips_mode',
253301
'_hashlib.HMAC.hexdigest',
254302
'_heapq.heappushpop_max',
255303
'_hmac.HMAC.hexdigest',
256304
'_io._IOBase.seek',
305+
'_io._IOBase.truncate',
257306
'_io._TextIOBase.detach',
307+
'_io._TextIOBase.read',
258308
'_io._WindowsConsoleIO.__init__',
309+
'_io.BytesIO.read1',
310+
'_io.BytesIO.writelines',
259311
'_io.FileIO.__init__',
312+
'_io.FileIO.close',
260313
'_io.FileIO.read',
261314
'_io.FileIO.readall',
262315
'_io.FileIO.seek',
316+
'_io.FileIO.write',
263317
'_io.open',
264318
'_io.open_code',
319+
'_io.StringIO.seek',
320+
'_io.TextIOWrapper.tell',
265321
'_lzma.LZMADecompressor.decompress',
266322
'_multibytecodec.MultibyteCodec.decode',
267323
'_multibytecodec.MultibyteCodec.encode',
324+
'_overlapped.Overlapped.getresult',
268325
'_posixshmem.shm_unlink',
269326
'_posixsubprocess.fork_exec',
327+
'_queue.SimpleQueue.get',
328+
'_queue.SimpleQueue.put',
270329
'_remote_debugging.RemoteUnwinder.__init__',
271330
'_remote_debugging.RemoteUnwinder.get_all_awaited_by',
272331
'_remote_debugging.RemoteUnwinder.get_async_stack_trace',
273332
'_remote_debugging.RemoteUnwinder.get_stack_trace',
274333
'_socket.socket.send',
334+
'_socket.socket.sendall',
335+
'_socket.socket.sendmsg',
275336
'_sqlite3.Blob.read',
276337
'_sqlite3.Blob.seek',
277338
'_sqlite3.Blob.write',
339+
'_sqlite3.Connection.__exit__',
278340
'_sqlite3.Connection.deserialize',
279341
'_sqlite3.Connection.serialize',
280342
'_sqlite3.Connection.set_progress_handler',
281343
'_sqlite3.Connection.setlimit',
344+
'_ssl._SSLContext.cert_store_stats',
345+
'_ssl._SSLContext.get_ca_certs',
282346
'_ssl._SSLContext.sni_callback',
283347
'_ssl._SSLSocket.context',
284348
'_ssl._SSLSocket.get_channel_binding',
285349
'_ssl._SSLSocket.sendfile',
286350
'_ssl.enum_certificates',
287351
'_ssl.RAND_status',
288352
'_testlimitedcapi.test_long_as_size_t',
353+
'_testmultiphase.StateAccessType.get_defining_module',
289354
'_tkinter.setbusywaitinterval',
290355
'_zstd.ZstdCompressor.__new__',
291356
'_zstd.ZstdCompressor.compress',
@@ -298,6 +363,7 @@
298363
'_zstd.ZstdDict.as_digested_dict',
299364
'_zstd.ZstdDict.as_prefix',
300365
'_zstd.ZstdDict.as_undigested_dict',
366+
'array.array.buffer_info',
301367
'array.array.byteswap',
302368
'array.array.fromunicode',
303369
'array.array.tounicode',
@@ -307,6 +373,7 @@
307373
'datetime.date.fromtimestamp',
308374
'datetime.datetime.__new__',
309375
'datetime.datetime.fromtimestamp',
376+
'datetime.time.isoformat',
310377
'datetime.time.strftime',
311378
'fcntl.fcntl',
312379
'fcntl.ioctl',
@@ -359,36 +426,52 @@
359426
'pyexpat.xmlparser.GetInputContext',
360427
'pyexpat.xmlparser.UseForeignDTD',
361428
'select.devpoll',
429+
'select.devpoll.poll',
430+
'select.epoll.poll',
362431
'select.poll',
432+
'select.poll.poll',
363433
'select.select',
364434
'signal.setitimer',
365435
'signal.signal',
366436
'signal.sigtimedwait',
367437
'signal.sigwait',
368-
'Struct.__init__',
438+
'Struct.__init__', # struct.Struct.__init__
439+
'Struct.unpack', # struct.Struct.unpack
369440
'termios.tcsetwinsize',
370441
'zlib.Decompress.decompress',
371442
'zlib.ZlibDecompressor.decompress',
372443

373444
# Objects/
445+
'bytearray.fromhex',
446+
'bytearray.join',
374447
'bytearray.maketrans',
375448
'bytearray.partition',
376449
'bytearray.replace',
377450
'bytearray.rpartition',
378451
'bytearray.rsplit',
379452
'bytearray.splitlines',
380453
'bytearray.strip',
454+
'bytearray.translate',
381455
'bytes.maketrans',
382456
'bytes.partition',
457+
'bytes.removeprefix',
458+
'bytes.removesuffix',
383459
'bytes.replace',
384460
'bytes.rpartition',
385461
'bytes.rsplit',
386462
'bytes.splitlines',
387463
'bytes.strip',
464+
'bytes.translate',
465+
'code._varname_from_oparg',
388466
'float.__getformat__',
389467
'list.sort',
390468
'memoryview.tobytes',
469+
'OrderedDict.popitem',
391470
'str.capitalize',
471+
'str.center',
472+
'str.count',
473+
'str.find',
474+
'str.index',
392475
'str.isalnum',
393476
'str.isalpha',
394477
'str.isdecimal',
@@ -399,10 +482,17 @@
399482
'str.isspace',
400483
'str.isupper',
401484
'str.join',
485+
'str.ljust',
486+
'str.maketrans',
402487
'str.partition',
403488
'str.removeprefix',
489+
'str.removesuffix',
404490
'str.replace',
491+
'str.rfind',
492+
'str.rindex',
493+
'str.rjust',
405494
'str.rpartition',
495+
'str.split',
406496
'str.splitlines',
407497
'str.title',
408498
'str.translate',
@@ -422,6 +512,7 @@
422512
'pow',
423513
'round',
424514
'sum',
515+
'_contextvars.Context.get',
425516
'_contextvars.ContextVar.get',
426517
'_contextvars.ContextVar.reset',
427518
'_contextvars.ContextVar.set',

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,31 +1516,27 @@ def format_docstring(self) -> str:
15161516
# between it and the {parameters} we're about to add.
15171517
lines.append('')
15181518

1519-
# PEP 8 requires that docstrings are limited to 72 characters:
1520-
#
1521-
# The Python standard library is conservative and requires
1522-
# limiting lines to 79 characters (and docstrings to 72).
1523-
#
15241519
# Fail if the summary line is too long.
15251520
# Warn if any of the body lines are too long.
15261521
# Existing violations are recorded in OVERLONG_{SUMMARY,BODY}.
1522+
max_width = f.docstring_line_width
15271523
summary_len = len(lines[0])
15281524
max_body = max(map(len, lines[1:]))
1529-
if summary_len > 72:
1525+
if summary_len > max_width:
15301526
if f.full_name not in OVERLONG_SUMMARY:
15311527
fail(f"Summary line for {f.full_name!r} is too long!\n"
1532-
f"The summary line must be no longer than 72 characters.")
1528+
f"The summary line must be no longer than {max_width} characters.")
15331529
else:
15341530
if f.full_name in OVERLONG_SUMMARY:
1535-
fail(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n")
1531+
warn(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n")
15361532

1537-
if max_body > 72:
1533+
if max_body > max_width:
15381534
if f.full_name not in OVERLONG_BODY:
15391535
warn(f"Docstring lines for {f.full_name!r} are too long!\n"
1540-
f"Lines should be no longer than 72 characters.")
1536+
f"Lines should be no longer than {max_width} characters.")
15411537
else:
15421538
if f.full_name in OVERLONG_BODY:
1543-
fail(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")
1539+
warn(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")
15441540

15451541
parameters_marker_count = len(f.docstring.split('{parameters}')) - 1
15461542
if parameters_marker_count > 1:

Tools/clinic/libclinic/function.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ def methoddef_flags(self) -> str | None:
167167
flags.append('METH_COEXIST')
168168
return '|'.join(flags)
169169

170+
@property
171+
def docstring_line_width(self) -> int:
172+
"""PEP 8 requires that docstrings are limited to 72 characters:
173+
174+
The Python standard library is conservative and requires
175+
limiting lines to 79 characters (and docstrings to 72).
176+
177+
Methods have an extra level of indentation, so we use 68.
178+
"""
179+
if self.cls is not None and not self.kind.new_or_init:
180+
return 68
181+
return 72
182+
170183
def __repr__(self) -> str:
171184
return f'<clinic.Function {self.name!r}>'
172185

0 commit comments

Comments
 (0)