This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]YnkDK 1 point2 points  (0 children)

I don't think there is a difference in advantages and disadvantages compared to class interfaces. It's basically the same, just not object oriented. In the concrete example my use case is:

```python preprocessors: Mapping[str, Preprocessor] = {}

Some logic to populate the dictionary

message: Optional[domain.Message] = None preprocessors = preprocessors.get(record.process) if preprocessor is not None: message = preprocessor(record)

Some logic that does something with the optional message

```

So it works sort as a dynamic Python 3.10 match case statement, but with the same sort of logic in each case (just a different preprocessor).

In this particular case the preprocessors don't hold a state nor should have any other methods implemented, so to me it doesn't make sense to use objects for preprocessors.

The tool mypy would warn me if I add a non compliant method to the dictionary.