script_bindings(python): Add ruff rule for strict typing in function (#38694)

This is part of introducing the Ruff rule [flake8-annotations
(ANN)](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) into
the script_bindings folder.

Since `codegen.py` has 10k lines of code, the strategy is to introduce
the rule first while ignoring the `ANN` Ruff rule for `codegen.py`. We
will then gradually add type annotations slice by slice to ensure no new
errors occur outside of `ANN`.

Testing: `./mach test-wpt webidl`

---------

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2025-08-18 15:26:30 +08:00 committed by GitHub
parent 27dededa65
commit 788d6db94d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 54 deletions

View file

@ -4,11 +4,14 @@
# Common codegen classes.
# fmt: off
from WebIDL import IDLUnionType
from WebIDL import IDLSequenceType
from collections import defaultdict
from itertools import groupby
from typing import Generator, Optional, cast
from typing import Optional
from collections.abc import Generator
from abc import abstractmethod
import operator
@ -2679,6 +2682,7 @@ def getAllTypes(
for d in descriptors:
for t in getTypesFromDescriptor(d):
if t.isRecord():
# pyrefly: ignore # missing-attribute
yield (t.inner, d)
yield (t, d)
for dictionary in dictionaries:
@ -4722,7 +4726,7 @@ pub(crate) fn init_{infoName}<D: DomTypes>() {{
assert isAlwaysInSlot or self.member.getExtendedAttribute("Cached")
isLazilyCachedInSlot = not isAlwaysInSlot
# pyrefly: ignore # unknown-name
slotIndex = memberReservedSlot(self.member) # noqa:FIXME: memberReservedSlot is not defined
slotIndex = memberReservedSlot(self.member) # noqa: F821 FIXME: memberReservedSlot is not defined
# We'll statically assert that this is not too big in
# CGUpdateMemberSlotsMethod, in the case when
# isAlwaysInSlot is true.