I agree that not writing any type annotations is the best, but that would require complex type inference. OCaml does type inference for it's duck-typed objective extension, but I'm not sure that such type inference is possible for a dynamic language like Python.
08.11.2013, 11:12, "Florian Weimer"
On 11/08/2013 11:08 AM, Vladimir Keleshev wrote:
You could also put asserts (and expressions which assert the presence of certain attributes) in function bodies. Nice idea—that seems to give more flexibility, but (probably) makes it harder to implement.
I would love to write:
assert hasattr(file_like, 'read') and hasattr(file_like, 'write')
Or maybe:
assert file_like.read and file_like.write
I actually expect something like this:
file_like.read(0) file_like.write("")
No assert statements, just straight-line code that is supposed to be easy to analyze. If the analyzer cannot use the information that file_like must have a callable read attribute that takes an integer argument, it could still use the information that a "read" attribute must be present.
-- Florian Weimer / Red Hat Product Security Team