Let's say I have a function dict_to_string:

>>> def dict_to_string(d: ??) -> str:
...     return ';'.join(f"{k},{v}" for k, v in vars(d).items())

What type hint is required to ensure that d has __dict__ and not __slots__, (or vice-versa, for future reference).

I know I can just check hasattr(d, '__dict__') and not __slots__, but I would like to know if it is possible to type hint.

0

There are 0 best solutions below