多くの言語は、アドホック ポリモーフィズム(別名関数のオーバーロード) をすぐにサポートします。ただし、Python はそれをオプトアウトしたようです。それでも、Python でそれをやってのけることができるトリックまたはライブラリがあるかもしれないと想像できます。そのようなツールを知っている人はいますか?
たとえば、Haskell では、これを使用してさまざまなタイプのテスト データを生成できます。
-- In some testing library:
class Randomizable a where
genRandom :: a
-- Overload for different types
instance Randomizable String where genRandom = ...
instance Randomizable Int where genRandom = ...
instance Randomizable Bool where genRandom = ...
-- In some client project, we might have a custom type:
instance Randomizable VeryCustomType where genRandom = ...
genRandom
これの優れた点は、テスト ライブラリに触れることなく、独自のカスタム型を拡張できることです。
Pythonでこのようなことをどのように達成しますか?