Skip to content

Commit

Permalink
[SymForce] Patch pybind11-stubgen __hash__ type
Browse files Browse the repository at this point in the history
Reviewers: danny,roy-v
GitOrigin-RevId: 8e8d563f2d12b95367157bba7690e4edfa47c7c3
  • Loading branch information
aaron-skydio committed Dec 21, 2024
1 parent 7b68222 commit 46bc0a7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions symforce/test_util/stubs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ def handle_class(
return maybe_class

pybind11_stubgen.parser.mixins.fix.FixNumpyArrayRemoveParameters.handle_class = handle_class # type: ignore[method-assign,assignment]


def patch_fix_missing_none_hash_field_annotation() -> None:
"""
See https://github.com/sizmailov/pybind11-stubgen/pull/236
"""

def handle_field(
self: pybind11_stubgen.parser.mixins.fix.FixMissingNoneHashFieldAnnotation,
path: pybind11_stubgen.structs.QualifiedName,
field: T.Any,
) -> T.Optional[pybind11_stubgen.structs.Field]:
result = super( # type: ignore[safe-super]
pybind11_stubgen.parser.mixins.fix.FixMissingNoneHashFieldAnnotation, self
).handle_field(path, field)
if result is None:
return None
if field is None and path[-1] == "__hash__":
result.attribute.annotation = self.parse_annotation_str("typing.ClassVar[typing.Any]")
return result

pybind11_stubgen.parser.mixins.fix.FixMissingNoneHashFieldAnnotation.handle_field = handle_field # type: ignore[method-assign]

0 comments on commit 46bc0a7

Please sign in to comment.