fix(report): add missing caption

This commit is contained in:
HEL
2026-07-23 11:57:12 +02:00
parent 8db90e4f83
commit 92038b7674
@@ -95,7 +95,6 @@ A second check in @fig:define_member:17 avoid redefining a member which is not a
case AppliedType(name=name, body=body, args=args):
generic: Type = self.get_type(name)
if not isinstance(generic, GenericType):
raise ValueError("AppliedType not derived from a GenericType")
@@ -124,7 +123,8 @@ A second check in @fig:define_member:17 avoid redefining a member which is not a
case _:
self.logger.debug(f"Can't get member on {type}")
return None
```
```,
caption: [Implementation of `TypesRegistry.lookup_member`]
) <fig:lookup_member>
Because we defined our internal type representations with dataclasses, we can easily leverage Python's pattern-matching capabilities to handle each case, as shown in @fig:lookup_member. The method is also quite straightforward though two things can be noted. The first is that looking up a member on `UnknownType` returns `UnknownType`. This basically tells the registry to go along with any references to unknown types, trusting the user that what they are doing is correct. It also allows gracefully propagating errors to avoid early returns that could be caused by raising an exception. The second important part of `lookup_member` is how `AppliedType` is handled. Since this type is derived from a generic type, its members may contain type variables. These are substituted lazily when referenced, i.e. in this method. `substitute_typevars` is a method which performs this substitution recursively given a mapping of type parameters to concrete type arguments. Its implementation is available in the repository in #code-ref(<substitute_typevars>, "midas/checker/types.py").