I believe the error was thrown because of the following reasons:
- When you define boo as a lambda: 'baa' at the class level, it behaves as a simple class attribute rather than an instance method. Lambdas are anonymous functions and they don't carry the metadata that is required to define a proper method signature. As a result, when inspect.signature tries to analyze the boo method, it fails because lambdas don't provide a full method signature in the context of being a class or instance method.
- In Python, methods defined inside a class using def are automatically wrapped into "bound methods" when accessed via an instance. This binding ensures the process receives the instance (self) as its first parameter. Lambdas defined as class attributes skip this behavior entirely, it means they don’t include the self parameter that is needed for instance methods.
- The inspect.signature function works with callable objects that follow Python's standards for functions or methods. Lambdas defined as class attributes don't meet all these requirements, that is why inspect.signature cannot analyze them properly.
These documents may be useful:
https://docs.python.org/3/reference/expressions.html#lambda
https://docs.python.org/3/library/inspect.html#inspect.signature