Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion Tools/clinic/libclinic/_overlong_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'_abc._abc_subclasscheck',
'_asyncio._swap_current_task',
'_codecs.lookup',
'_collections.deque.rotate',
'_ctypes.byref',
'_curses.assume_default_colors',
'_curses.can_change_color',
Expand All @@ -25,6 +26,8 @@
'_curses.start_color',
'_curses.termname',
'_curses.window.enclose',
'_curses.window.is_linetouched',
'_curses.window.putwin',
'_elementtree._set_factories',
'_functools.reduce',
'_gdbm.gdbm.setdefault',
Expand All @@ -34,16 +37,21 @@
'_hashlib.pbkdf2_hmac',
'_heapq.heappushpop',
'_hmac.HMAC.hexdigest',
'_interpreters.get_config',
'_interpreters.is_shareable',
'_io._BufferedIOBase.read1',
'_io.FileIO.truncate',
'_lzma._decode_filter_properties',
'_opcode.has_name',
'_remote_debugging.RemoteUnwinder.__init__',
'_remote_debugging.RemoteUnwinder.get_all_awaited_by',
'_remote_debugging.RemoteUnwinder.get_async_stack_trace',
'_socket.if_indextoname',
'_socket.inet_aton',
'_sqlite3.Connection.set_trace_callback',
'_sre.SRE_Match.expand',
'_sre.SRE_Match.groupdict',
'_sre.SRE_Match.span',
'_sre.SRE_Pattern.finditer',
'_sre.SRE_Pattern.search',
'_sre.SRE_Pattern.sub',
Expand All @@ -63,13 +71,16 @@
'_tracemalloc.reset_peak',
'_zstd.get_frame_size',
'_zstd.set_parameter_types',
'_zstd.ZstdCompressor.set_pledged_input_size',
'_zstd.ZstdDecompressor.decompress',
'array.array.buffer_info',
'array.array.frombytes',
'array.array.fromfile',
'array.array.tobytes',
'cmath.isfinite',
'datetime.date.strptime',
'datetime.datetime.strptime',
'datetime.time.strptime',
'gc.freeze',
'gc.get_objects',
'itertools.batched.__new__',
Expand Down Expand Up @@ -109,18 +120,27 @@
'os.WTERMSIG',
'pwd.getpwall',
'pyexpat.xmlparser.ExternalEntityParserCreate',
'pyexpat.xmlparser.GetInputContext',
'pyexpat.xmlparser.GetReparseDeferralEnabled',
'pyexpat.xmlparser.SetParamEntityParsing',
'pyexpat.xmlparser.SetReparseDeferralEnabled',
'pyexpat.xmlparser.UseForeignDTD',
'readline.get_history_length',
'readline.redisplay',
'readline.set_history_length',
'select.epoll.register',
'signal.set_wakeup_fd',
'unpack', # struct.unpack
'unpack_from', # struct.unpack_from
'termios.tcdrain',
'unicodedata.UCD.bidirectional',
'unicodedata.UCD.category',
'unicodedata.UCD.combining',
'unicodedata.UCD.decomposition',
'unicodedata.UCD.east_asian_width',
'unicodedata.UCD.is_normalized',
'unicodedata.UCD.mirrored',
'zlib.Decompress.decompress',
'zoneinfo.ZoneInfo.dst',
'zoneinfo.ZoneInfo.tzname',
'zoneinfo.ZoneInfo.utcoffset',
Expand All @@ -139,35 +159,53 @@
'bytearray.split',
'bytearray.splitlines',
'bytearray.startswith',
'bytearray.translate',
'bytes.count',
'bytes.endswith',
'bytes.find',
'bytes.index',
'bytes.maketrans',
'bytes.removeprefix',
'bytes.removesuffix',
'bytes.rfind',
'bytes.rindex',
'bytes.rsplit',
'bytes.split',
'bytes.splitlines',
'bytes.startswith',
'bytes.translate',
'code.replace',
'complex.conjugate',
'dict.fromkeys',
'dict.pop',
'float.as_integer_ratio',
'frame.f_generator',
'frame.f_trace',
'int.bit_count',
'int.is_integer',
'OrderedDict.fromkeys',
'OrderedDict.pop',
'set.difference',
'set.symmetric_difference',
'set.symmetric_difference_update',
'str.__format__',
'str.count',
'str.endswith',
'str.find',
'str.index',
'str.isalnum',
'str.isascii',
'str.isidentifier',
'str.isprintable',
'str.rfind',
'str.rindex',
'str.rsplit',
'str.split',
'str.splitlines',
'str.startswith',
'str.strip',
'str.swapcase',
'str.translate',
'str.zfill',

# PC/
Expand All @@ -179,12 +217,15 @@
'isinstance',
'pow',
'sum',
'_contextvars.Context.get',
'_contextvars.ContextVar.set',
'_imp._override_multi_interp_extensions_check',
'_imp.find_frozen',
'_jit.is_active',
'_jit.is_available',
'_jit.is_enabled',
'marshal.dumps',
'sys._clear_type_descriptors',
'sys._current_exceptions',
'sys._current_frames',
'sys._setprofileallthreads',
Expand All @@ -197,6 +238,10 @@

# Modules/
'_abc.get_cache_token',
'_asyncio.Future.add_done_callback',
'_asyncio.Future.cancel',
'_asyncio.Future.done',
'_asyncio.Future.result',
'_bisect.bisect_left',
'_bisect.bisect_right',
'_bz2.BZ2Decompressor.decompress',
Expand Down Expand Up @@ -232,12 +277,14 @@
'_curses.tigetstr',
'_curses.use_env',
'_curses.window.border',
'_curses.window.box',
'_curses.window.derwin',
'_curses.window.getch',
'_curses.window.getkey',
'_curses.window.inch',
'_curses.window.insch',
'_curses.window.insnstr',
'_curses.window.insstr',
'_curses.window.is_linetouched',
'_curses.window.noutrefresh',
'_curses.window.overlay',
Expand All @@ -248,44 +295,67 @@
'_curses.window.touchline',
'_curses_panel.panel.hide',
'_curses_panel.update_panels',
'_dbm.dbm.setdefault',
'_functools.reduce',
'_gdbm.gdbm.firstkey',
'_gdbm.gdbm.nextkey',
'_gdbm.gdbm.reorganize',
'_hashlib.get_fips_mode',
'_hashlib.HMAC.hexdigest',
'_heapq.heappushpop_max',
'_hmac.HMAC.hexdigest',
'_interpreters.capture_exception',
'_interpreters.run_func',
'_io._IOBase.seek',
'_io._IOBase.truncate',
'_io._TextIOBase.detach',
'_io._TextIOBase.read',
'_io._WindowsConsoleIO.__init__',
'_io.BytesIO.read1',
'_io.BytesIO.writelines',
'_io.FileIO.__init__',
'_io.FileIO.close',
'_io.FileIO.read',
'_io.FileIO.readall',
'_io.FileIO.seek',
'_io.FileIO.write',
'_io.open',
'_io.open_code',
'_io.StringIO.seek',
'_io.TextIOWrapper.tell',
'_lzma.LZMADecompressor.decompress',
'_multibytecodec.MultibyteCodec.decode',
'_multibytecodec.MultibyteCodec.encode',
'_overlapped.Overlapped.getresult',
'_posixshmem.shm_unlink',
'_posixsubprocess.fork_exec',
'_queue.SimpleQueue.get',
'_queue.SimpleQueue.put',
'_remote_debugging.RemoteUnwinder.__init__',
'_remote_debugging.RemoteUnwinder.get_all_awaited_by',
'_remote_debugging.RemoteUnwinder.get_async_stack_trace',
'_remote_debugging.RemoteUnwinder.get_stack_trace',
'_socket.socket.send',
'_socket.socket.sendall',
'_socket.socket.sendmsg',
'_sqlite3.Blob.read',
'_sqlite3.Blob.seek',
'_sqlite3.Blob.write',
'_sqlite3.Connection.__exit__',
'_sqlite3.Connection.deserialize',
'_sqlite3.Connection.serialize',
'_sqlite3.Connection.set_progress_handler',
'_sqlite3.Connection.setlimit',
'_ssl._SSLContext.cert_store_stats',
'_ssl._SSLContext.get_ca_certs',
'_ssl._SSLContext.sni_callback',
'_ssl._SSLSocket.context',
'_ssl._SSLSocket.get_channel_binding',
'_ssl._SSLSocket.sendfile',
'_ssl.enum_certificates',
'_ssl.RAND_status',
'_testlimitedcapi.test_long_as_size_t',
'_testmultiphase.StateAccessType.get_defining_module',
'_tkinter.setbusywaitinterval',
'_zstd.ZstdCompressor.__new__',
'_zstd.ZstdCompressor.compress',
Expand All @@ -298,6 +368,7 @@
'_zstd.ZstdDict.as_digested_dict',
'_zstd.ZstdDict.as_prefix',
'_zstd.ZstdDict.as_undigested_dict',
'array.array.buffer_info',
'array.array.byteswap',
'array.array.fromunicode',
'array.array.tounicode',
Expand All @@ -307,6 +378,7 @@
'datetime.date.fromtimestamp',
'datetime.datetime.__new__',
'datetime.datetime.fromtimestamp',
'datetime.time.isoformat',
'datetime.time.strftime',
'fcntl.fcntl',
'fcntl.ioctl',
Expand Down Expand Up @@ -359,36 +431,52 @@
'pyexpat.xmlparser.GetInputContext',
'pyexpat.xmlparser.UseForeignDTD',
'select.devpoll',
'select.devpoll.poll',
'select.epoll.poll',
'select.poll',
'select.poll.poll',
'select.select',
'signal.setitimer',
'signal.signal',
'signal.sigtimedwait',
'signal.sigwait',
'Struct.__init__',
'Struct.__init__', # struct.Struct.__init__
'Struct.unpack', # struct.Struct.unpack
'termios.tcsetwinsize',
'zlib.Decompress.decompress',
'zlib.ZlibDecompressor.decompress',

# Objects/
'bytearray.fromhex',
'bytearray.join',
'bytearray.maketrans',
'bytearray.partition',
'bytearray.replace',
'bytearray.rpartition',
'bytearray.rsplit',
'bytearray.splitlines',
'bytearray.strip',
'bytearray.translate',
'bytes.maketrans',
'bytes.partition',
'bytes.removeprefix',
'bytes.removesuffix',
'bytes.replace',
'bytes.rpartition',
'bytes.rsplit',
'bytes.splitlines',
'bytes.strip',
'bytes.translate',
'code._varname_from_oparg',
'float.__getformat__',
'list.sort',
'memoryview.tobytes',
'OrderedDict.popitem',
'str.capitalize',
'str.center',
'str.count',
'str.find',
'str.index',
'str.isalnum',
'str.isalpha',
'str.isdecimal',
Expand All @@ -399,10 +487,17 @@
'str.isspace',
'str.isupper',
'str.join',
'str.ljust',
'str.maketrans',
'str.partition',
'str.removeprefix',
'str.removesuffix',
'str.replace',
'str.rfind',
'str.rindex',
'str.rjust',
'str.rpartition',
'str.split',
'str.splitlines',
'str.title',
'str.translate',
Expand All @@ -422,6 +517,7 @@
'pow',
'round',
'sum',
'_contextvars.Context.get',
'_contextvars.ContextVar.get',
'_contextvars.ContextVar.reset',
'_contextvars.ContextVar.set',
Expand Down
18 changes: 7 additions & 11 deletions Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,31 +1516,27 @@ def format_docstring(self) -> str:
# between it and the {parameters} we're about to add.
lines.append('')

# PEP 8 requires that docstrings are limited to 72 characters:
#
# The Python standard library is conservative and requires
# limiting lines to 79 characters (and docstrings to 72).
#
# Fail if the summary line is too long.
# Warn if any of the body lines are too long.
# Existing violations are recorded in OVERLONG_{SUMMARY,BODY}.
max_width = f.docstring_line_width
summary_len = len(lines[0])
max_body = max(map(len, lines[1:]))
if summary_len > 72:
if summary_len > max_width:
if f.full_name not in OVERLONG_SUMMARY:
fail(f"Summary line for {f.full_name!r} is too long!\n"
f"The summary line must be no longer than 72 characters.")
f"The summary line must be no longer than {max_width} characters.")
else:
if f.full_name in OVERLONG_SUMMARY:
fail(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n")
warn(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n")

if max_body > 72:
if max_body > max_width:
if f.full_name not in OVERLONG_BODY:
warn(f"Docstring lines for {f.full_name!r} are too long!\n"
f"Lines should be no longer than 72 characters.")
f"Lines should be no longer than {max_width} characters.")
else:
if f.full_name in OVERLONG_BODY:
fail(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")
warn(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")

parameters_marker_count = len(f.docstring.split('{parameters}')) - 1
if parameters_marker_count > 1:
Expand Down
2 changes: 1 addition & 1 deletion Tools/clinic/libclinic/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __post_init__(self) -> None:
def report(self, *, warn_only: bool = False) -> str:
msg = "Warning" if warn_only else "Error"
if self.filename is not None:
msg += f" in file '{self.filename}'"
msg += f" in file {self.filename!r}"
if self.lineno is not None:
msg += f" on line {self.lineno}"
msg += ":\n"
Expand Down
Loading
Loading