Skip to content

Commit 937270d

Browse files
AvasamAlexWaygood
andauthored
Forbid extremely long line lengths in non-autogenerated stubs (#12537)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent eca1df4 commit 937270d

File tree

15 files changed

+69
-27
lines changed

15 files changed

+69
-27
lines changed

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ line-length = 130
33
target-version = ["py310"]
44
skip-magic-trailing-comma = true
55
# Exclude protobuf files because they have long line lengths
6+
# that can't be autofixed. Like docstrings and import aliases.
67
# Ideally, we could configure Black to allow longer line lengths
78
# for just these files, but doesn't seem possible yet.
89
force-exclude = ".*_pb2.pyi"
@@ -91,13 +92,16 @@ ignore = [
9192
# B033 could be slightly useful but Ruff doesn't have per-file select
9293
"B", # flake8-bugbear
9394
# Rules that are out of the control of stub authors:
94-
"E501", # Line too long
9595
"E741", # ambiguous variable name
9696
"F403", # `from . import *` used; unable to detect undefined names
9797
# Stubs can sometimes re-export entire modules.
9898
# Issues with using a star-imported name will be caught by type-checkers.
9999
"F405", # may be undefined, or defined from star imports
100100
]
101+
# See comment on black's force-exclude config above
102+
"*_pb2.pyi" = [
103+
"E501", # Line too long
104+
]
101105

102106
[tool.ruff.lint.isort]
103107
split-on-trailing-comma = false

stdlib/builtins.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet,
3333
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
3434
from types import CellType, CodeType, TracebackType
3535

36-
# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping} are imported from collections.abc in builtins.pyi
36+
# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping}
37+
# are imported from collections.abc in builtins.pyi
3738
from typing import ( # noqa: Y022
3839
IO,
3940
Any,
@@ -1084,7 +1085,8 @@ class dict(MutableMapping[_KT, _VT]):
10841085
def keys(self) -> dict_keys[_KT, _VT]: ...
10851086
def values(self) -> dict_values[_KT, _VT]: ...
10861087
def items(self) -> dict_items[_KT, _VT]: ...
1087-
# Signature of `dict.fromkeys` should be kept identical to `fromkeys` methods of `OrderedDict`/`ChainMap`/`UserDict` in `collections`
1088+
# Signature of `dict.fromkeys` should be kept identical to
1089+
# `fromkeys` methods of `OrderedDict`/`ChainMap`/`UserDict` in `collections`
10881090
# TODO: the true signature of `dict.fromkeys` is not expressible in the current type system.
10891091
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
10901092
@classmethod

stdlib/collections/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ class ChainMap(MutableMapping[_KT, _VT]):
475475
def pop(self, key: _KT, default: _T) -> _VT | _T: ...
476476
def copy(self) -> Self: ...
477477
__copy__ = copy
478-
# All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`.
478+
# All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime,
479+
# so the signature should be kept in line with `dict.fromkeys`.
479480
@classmethod
480481
@overload
481482
def fromkeys(cls, iterable: Iterable[_T]) -> ChainMap[_T, Any | None]: ...

stdlib/email/message.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class Message(Generic[_HeaderT, _HeaderParamT]):
5050
def get_payload(self, i: None = None, *, decode: Literal[True]) -> _EncodedPayloadType | Any: ...
5151
@overload # not multipart, IDEM but w/o kwarg
5252
def get_payload(self, i: None, decode: Literal[True]) -> _EncodedPayloadType | Any: ...
53-
# If `charset=None` and payload supports both `encode` AND `decode`, then an invalid payload could be passed, but this is unlikely
53+
# If `charset=None` and payload supports both `encode` AND `decode`,
54+
# then an invalid payload could be passed, but this is unlikely
5455
# Not[_SupportsEncodeToPayload]
5556
@overload
5657
def set_payload(

stdlib/ftplib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class FTP:
8686
def makeport(self) -> socket: ...
8787
def makepasv(self) -> tuple[str, int]: ...
8888
def login(self, user: str = "", passwd: str = "", acct: str = "") -> str: ...
89-
# In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers.
89+
# In practice, `rest` can actually be anything whose str() is an integer sequence, so to make it simple we allow integers
9090
def ntransfercmd(self, cmd: str, rest: int | str | None = None) -> tuple[socket, int | None]: ...
9191
def transfercmd(self, cmd: str, rest: int | str | None = None) -> socket: ...
9292
def retrbinary(

stdlib/os/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ class stat_result(structseq[float], tuple[int, int, int, int, int, int, int, flo
365365
if sys.version_info >= (3, 12) and sys.platform == "win32":
366366
@property
367367
@deprecated(
368-
"Use st_birthtime instead to retrieve the file creation time. In the future, this property will contain the last metadata change time."
368+
"""\
369+
Use st_birthtime instead to retrieve the file creation time. \
370+
In the future, this property will contain the last metadata change time."""
369371
)
370372
def st_ctime(self) -> float: ...
371373
else:

stdlib/poplib.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ class POP3_SSL(POP3):
6767
timeout: float = ...,
6868
context: ssl.SSLContext | None = None,
6969
) -> None: ...
70-
# "context" is actually the last argument, but that breaks LSP and it doesn't really matter because all the arguments are ignored
70+
# "context" is actually the last argument,
71+
# but that breaks LSP and it doesn't really matter because all the arguments are ignored
7172
def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> NoReturn: ...

stdlib/tkinter/ttk.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ class Notebook(Widget):
556556
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
557557
padding: _Padding = ...,
558558
text: str = ...,
559-
image=..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
559+
# `image` is a sequence of an image name, followed by zero or more
560+
# (sequences of one or more state names followed by an image name)
561+
image=...,
560562
compound: tkinter._Compound = ...,
561563
underline: int = ...,
562564
) -> None: ...

stubs/openpyxl/openpyxl/cell/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date, datetime, time, timedelta
22
from decimal import Decimal
3+
from typing import Any
34
from typing_extensions import TypeAlias
45

56
from openpyxl.cell.rich_text import CellRichText
@@ -20,3 +21,4 @@ _CellValue: TypeAlias = ( # noqa: Y047 # Used in other modules
2021
| DataTableFormula
2122
| ArrayFormula
2223
)
24+
_AnyCellValue: TypeAlias = Any # Any of _CellValue # noqa: Y047 # Used in other modules

stubs/openpyxl/openpyxl/chart/series.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ class Series(Serialisable):
8383
explosion: _HasTagAndGet[ConvertibleToInt | None] | ConvertibleToInt | None = None,
8484
extLst: Unused = None,
8585
) -> None: ...
86-
def to_tree(self, tagname: str | None = None, idx: _HasTagAndGet[ConvertibleToInt] | ConvertibleToInt | None = None) -> Element: ... # type: ignore[override]
86+
def to_tree( # type: ignore[override]
87+
self, tagname: str | None = None, idx: _HasTagAndGet[ConvertibleToInt] | ConvertibleToInt | None = None
88+
) -> Element: ...
8789

8890
class XYSeries(Series):
8991
# Same as parent

0 commit comments

Comments
 (0)