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
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality