Skip to content

Commit 937270d

Browse files
AvasamAlexWaygood
andauthored
Forbid extremely long line lengths in non-autogenerated stubs (#12537)
Co-authored-by: Alex Waygood <[email protected]>
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

stubs/openpyxl/openpyxl/worksheet/_reader.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from _typeshed import Incomplete, SupportsGetItem, Unused
22
from collections.abc import Container, Generator
33
from datetime import datetime
4-
from typing import Any, Final
4+
from typing import Final
55
from xml.etree.ElementTree import _FileRead
66

7+
from openpyxl.cell import _AnyCellValue
78
from openpyxl.cell.cell import Cell
89
from openpyxl.cell.rich_text import CellRichText
910
from openpyxl.descriptors.serialisable import _ChildSerialisableTreeElement, _SerialisableTreeElement
@@ -86,12 +87,10 @@ class WorkSheetParser:
8687
) -> None: ...
8788
def parse(self) -> Generator[Incomplete, None, None]: ...
8889
def parse_dimensions(self) -> _RangeBoundariesTuple | None: ...
89-
# AnyOf[time, date, datetime, timedelta, float, int, bool, str, ArrayFormula, DataTableFormula, Translator, Text, TextBlock, CellRichText, None]
90-
def parse_cell(self, element) -> dict[str, Any]: ...
90+
def parse_cell(self, element) -> dict[str, _AnyCellValue]: ...
9191
def parse_formula(self, element): ...
9292
def parse_column_dimensions(self, col: _HasAttrib) -> None: ...
93-
# Any: Same as parse_cell
94-
def parse_row(self, row: _SupportsIterAndAttrib) -> tuple[int, list[dict[str, Any]]]: ...
93+
def parse_row(self, row: _SupportsIterAndAttrib) -> tuple[int, list[dict[str, _AnyCellValue]]]: ...
9594
def parse_formatting(self, element: _ChildSerialisableTreeElement) -> None: ...
9695
def parse_sheet_protection(self, element: _SerialisableTreeElement) -> None: ...
9796
def parse_extensions(self, element: _ChildSerialisableTreeElement) -> None: ...

stubs/passlib/passlib/utils/handlers.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ class HasManyIdents(GenericHandler):
8484
ident_aliases: ClassVar[dict[str, str] | None]
8585
ident: str # type: ignore[misc]
8686
@classmethod
87-
def using(cls, default_ident: Incomplete | None = None, ident: Incomplete | None = None, **kwds): ... # type: ignore[override]
87+
def using( # type: ignore[override]
88+
cls, default_ident: Incomplete | None = None, ident: Incomplete | None = None, **kwds
89+
): ...
8890
def __init__(self, ident: Incomplete | None = None, **kwds) -> None: ...
8991

9092
class HasSalt(GenericHandler):
@@ -95,7 +97,9 @@ class HasSalt(GenericHandler):
9597
default_salt_chars: ClassVar[str | None]
9698
salt: str | bytes | None
9799
@classmethod
98-
def using(cls, default_salt_size: int | None = None, salt_size: int | None = None, salt: str | bytes | None = None, **kwds): ... # type: ignore[override]
100+
def using( # type: ignore[override]
101+
cls, default_salt_size: int | None = None, salt_size: int | None = None, salt: str | bytes | None = None, **kwds
102+
): ...
99103
def __init__(self, salt: str | bytes | None = None, **kwds) -> None: ...
100104
@classmethod
101105
def bitsize(cls, salt_size: int | None = None, **kwds): ...

stubs/psycopg2/psycopg2/_psycopg.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ConnectionInfo:
217217
# [1]: https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ConnectionInfo
218218
# [2]: https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L52 and below
219219
# [3]: https://www.postgresql.org/docs/current/libpq-status.html
220-
# [4]: https://github.com/postgres/postgres/blob/b39838889e76274b107935fa8e8951baf0e8b31b/src/interfaces/libpq/fe-connect.c#L6754 and below
220+
# [4]: https://github.com/postgres/postgres/blob/b39838889e76274b107935fa8e8951baf0e8b31b/src/interfaces/libpq/fe-connect.c#L6754 and below # noqa: E501
221221
@property
222222
def backend_pid(self) -> int: ...
223223
@property

stubs/redis/redis/client.pyi

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ class Pipeline(Redis[_StrType]):
485485
def slowlog_reset(self) -> Pipeline[_StrType]: ... # type: ignore[override]
486486
def time(self) -> Pipeline[_StrType]: ... # type: ignore[override]
487487
def append(self, key, value) -> Pipeline[_StrType]: ...
488-
def bitcount(self, key: _Key, start: int | None = None, end: int | None = None, mode: str | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
488+
def bitcount( # type: ignore[override]
489+
self, key: _Key, start: int | None = None, end: int | None = None, mode: str | None = None
490+
) -> Pipeline[_StrType]: ...
489491
def bitop(self, operation, dest, *keys) -> Pipeline[_StrType]: ...
490492
def bitpos(self, key, bit, start=None, end=None, mode: str | None = None) -> Pipeline[_StrType]: ...
491493
def decr(self, name, amount=1) -> Pipeline[_StrType]: ... # type: ignore[override]
@@ -494,7 +496,9 @@ class Pipeline(Redis[_StrType]):
494496
def dump(self, name) -> Pipeline[_StrType]: ... # type: ignore[override]
495497
def exists(self, *names: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]
496498
def __contains__(self, *names: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]
497-
def expire(self, name: _Key, time: int | timedelta, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False) -> Pipeline[_StrType]: ... # type: ignore[override]
499+
def expire( # type: ignore[override]
500+
self, name: _Key, time: int | timedelta, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False
501+
) -> Pipeline[_StrType]: ...
498502
def expireat(
499503
self, name, when, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False
500504
) -> Pipeline[_StrType]: ...
@@ -512,8 +516,12 @@ class Pipeline(Redis[_StrType]):
512516
def msetnx(self, mapping: Mapping[_Key, _Value]) -> Pipeline[_StrType]: ... # type: ignore[override]
513517
def move(self, name: _Key, db: int) -> Pipeline[_StrType]: ... # type: ignore[override]
514518
def persist(self, name: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]
515-
def pexpire(self, name: _Key, time: int | timedelta, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False) -> Pipeline[_StrType]: ... # type: ignore[override]
516-
def pexpireat(self, name: _Key, when: int | datetime, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False) -> Pipeline[_StrType]: ... # type: ignore[override]
519+
def pexpire( # type: ignore[override]
520+
self, name: _Key, time: int | timedelta, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False
521+
) -> Pipeline[_StrType]: ...
522+
def pexpireat( # type: ignore[override]
523+
self, name: _Key, when: int | datetime, nx: bool = False, xx: bool = False, gt: bool = False, lt: bool = False
524+
) -> Pipeline[_StrType]: ...
517525
def psetex(self, name, time_ms, value) -> Pipeline[_StrType]: ...
518526
def pttl(self, name) -> Pipeline[_StrType]: ... # type: ignore[override]
519527
def randomkey(self) -> Pipeline[_StrType]: ... # type: ignore[override]
@@ -598,7 +606,9 @@ class Pipeline(Redis[_StrType]):
598606
store: _Key | None = None,
599607
groups: bool = False,
600608
) -> Pipeline[_StrType]: ...
601-
def scan(self, cursor: int = 0, match: _Key | None = None, count: int | None = None, _type: str | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
609+
def scan( # type: ignore[override]
610+
self, cursor: int = 0, match: _Key | None = None, count: int | None = None, _type: str | None = None
611+
) -> Pipeline[_StrType]: ...
602612
def scan_iter(self, match: _Key | None = None, count: int | None = None, _type: str | None = None) -> Iterator[Any]: ... # type: ignore[override]
603613
def sscan(self, name: _Key, cursor: int = 0, match: _Key | None = None, count: int | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
604614
def sscan_iter(self, name: _Key, match: _Key | None = None, count: int | None = None) -> Iterator[Any]: ...
@@ -680,7 +690,9 @@ class Pipeline(Redis[_StrType]):
680690
def zcard(self, name: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]
681691
def zcount(self, name: _Key, min: _Value, max: _Value) -> Pipeline[_StrType]: ... # type: ignore[override]
682692
def zincrby(self, name: _Key, amount: float, value: _Value) -> Pipeline[_StrType]: ... # type: ignore[override]
683-
def zinterstore(self, dest: _Key, keys: Iterable[_Key], aggregate: Literal["SUM", "MIN", "MAX"] | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
693+
def zinterstore( # type: ignore[override]
694+
self, dest: _Key, keys: Iterable[_Key], aggregate: Literal["SUM", "MIN", "MAX"] | None = None
695+
) -> Pipeline[_StrType]: ...
684696
def zlexcount(self, name: _Key, min: _Value, max: _Value) -> Pipeline[_StrType]: ... # type: ignore[override]
685697
def zpopmax(self, name: _Key, count: int | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
686698
def zpopmin(self, name: _Key, count: int | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
@@ -699,7 +711,9 @@ class Pipeline(Redis[_StrType]):
699711
offset: int | None = None,
700712
num: int | None = None,
701713
) -> Pipeline[_StrType]: ...
702-
def zrangebylex(self, name: _Key, min: _Value, max: _Value, start: int | None = None, num: int | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
714+
def zrangebylex( # type: ignore[override]
715+
self, name: _Key, min: _Value, max: _Value, start: int | None = None, num: int | None = None
716+
) -> Pipeline[_StrType]: ...
703717
def zrangebyscore( # type: ignore[override]
704718
self,
705719
name: _Key,
@@ -733,7 +747,9 @@ class Pipeline(Redis[_StrType]):
733747
) -> Pipeline[_StrType]: ...
734748
def zrevrank(self, name: _Key, value: _Value, withscore: bool = False) -> Pipeline[_StrType]: ... # type: ignore[override]
735749
def zscore(self, name: _Key, value: _Value) -> Pipeline[_StrType]: ... # type: ignore[override]
736-
def zunionstore(self, dest: _Key, keys: Iterable[_Key], aggregate: Literal["SUM", "MIN", "MAX"] | None = None) -> Pipeline[_StrType]: ... # type: ignore[override]
750+
def zunionstore( # type: ignore[override]
751+
self, dest: _Key, keys: Iterable[_Key], aggregate: Literal["SUM", "MIN", "MAX"] | None = None
752+
) -> Pipeline[_StrType]: ...
737753
def pfadd(self, name: _Key, *values: _Value) -> Pipeline[_StrType]: ... # type: ignore[override]
738754
def pfcount(self, name: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]
739755
def pfmerge(self, dest: _Key, *sources: _Key) -> Pipeline[_StrType]: ... # type: ignore[override]

stubs/reportlab/reportlab/platypus/doctemplate.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,10 @@ class BaseDocTemplate:
264264

265265
class SimpleDocTemplate(BaseDocTemplate):
266266
def handle_pageBegin(self) -> None: ...
267-
def build(self, flowables: list[Flowable], onFirstPage: _PageCallback = ..., onLaterPages: _PageCallback = ..., canvasmaker: _CanvasMaker = ...) -> None: ... # type: ignore[override]
267+
def build( # type: ignore[override]
268+
self,
269+
flowables: list[Flowable],
270+
onFirstPage: _PageCallback = ...,
271+
onLaterPages: _PageCallback = ...,
272+
canvasmaker: _CanvasMaker = ...,
273+
) -> None: ...

0 commit comments

Comments
 (0)