3 ms·
Has anyone ever tried to implement optional typing in python with just generators? It seems like a generator like @Signature(...input types, output type) would
by hardwaresofton 11y ago
Has anyone ever tried to implement optional typing in python with just generators?
It seems like a generator like @Signature(...input types, output type) would solve this problem with limited language changes, and would work in python 2/3?
- justusw 11y agoDo you mean decorators? A solution like that exists and has been used for a while. It really is only usable for run-time type-checks. See here: https://github.com/dobarkod/typedecorator https://github.com/dobarkod/typedecorator With type annotations you can have static guarantees, which decorators will not be able to provide, as decorator methods will be called and resolved only during runtime. Objects imported from `types` hopefully will not.
- hardwaresofton 11y agoYeah, that's what I meant to type, thanks. https://github.com/dobarkod/typedecorator https://github.com/dobarkod/typedecorator is interesting -- I was imagining type signatures more like haskell's: addNumber :: Int -> Int -> Int translating to something like @TypeSignature([int, int, int]) def add_number(a,b): .... It's just as possible to have the compile-time program that's doing the checking process the decorators.
- deleted 11y ago[deleted]