script_bindings: Add type definitions for configuration.py (#38450)

*Describe the changes that this pull request makes here. This will be
the commit message.*

Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*

---------

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2025-08-06 13:44:05 +08:00 committed by GitHub
parent 62b181dc85
commit 5b148cf5de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 45 deletions

View file

@ -136,10 +136,9 @@ def isDomInterface(t: IDLObject, logging: bool = False) -> bool:
t = t.inner
if isinstance(t, IDLInterface):
return True
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLType)
if t.isCallback() or t.isPromise():
return True
# pyrefly: ignore # missing-attribute
return t.isInterface() and (t.isSpiderMonkeyInterface() and not t.isBufferSource())
@ -160,9 +159,9 @@ def containsDomInterface(t: IDLObject, logging: bool = False) -> bool:
return any(map(lambda x: containsDomInterface(x), t.members)) or (t.parent and containsDomInterface(t.parent))
if isDomInterface(t):
return True
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLType)
if t.isSequence():
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLSequenceType)
return containsDomInterface(t.inner)
return False
@ -2674,11 +2673,13 @@ def getAllTypes(
for dictionary in dictionaries:
for t in getTypesFromDictionary(dictionary):
if t.isRecord():
# pyrefly: ignore # missing-attribute
yield (t.inner, None)
yield (t, None)
for callback in callbacks:
for t in getTypesFromCallback(callback):
if t.isRecord():
# pyrefly: ignore # missing-attribute
yield (t.inner, None)
yield (t, None)
for typedef in typedefs:
@ -2713,7 +2714,7 @@ def UnionTypes(
t = t.unroll()
if not t.isUnion():
continue
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLUnionType) and t.flatMemberTypes is not None
for memberType in t.flatMemberTypes:
if memberType.isDictionary() or memberType.isEnum() or memberType.isCallback():
memberModule = getModuleFromObject(memberType)
@ -7828,43 +7829,38 @@ def type_needs_tracing(t: IDLObject):
assert isinstance(t, IDLObject), (t, type(t))
if t.isType():
assert isinstance(t, IDLType)
if isinstance(t, IDLWrapperType):
return type_needs_tracing(t.inner)
# pyrefly: ignore # missing-attribute
if t.nullable():
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLNullableType)
return type_needs_tracing(t.inner)
# pyrefly: ignore # missing-attribute
if t.isAny():
return True
# pyrefly: ignore # missing-attribute
if t.isObject():
return True
# pyrefly: ignore # missing-attribute
if t.isSequence() :
# pyrefly: ignore # missing-attribute
assert isinstance(t, IDLSequenceType)
return type_needs_tracing(t.inner)
if t.isUnion():
# pyrefly: ignore # not-iterable
assert isinstance(t, IDLUnionType) and t.flatMemberTypes is not None
return any(type_needs_tracing(member) for member in t.flatMemberTypes)
# pyrefly: ignore # bad-argument-type
if is_typed_array(t):
return True
return False
if t.isDictionary():
# pyrefly: ignore # missing-attribute, bad-argument-type
assert isinstance(t, IDLDictionary)
if t.parent and type_needs_tracing(t.parent):
return True
# pyrefly: ignore # missing-attribute
if any(type_needs_tracing(member.type) for member in t.members):
return True