What's the best way to minimize the need of run time checks?

Michael Selik michael.selik at gmail.com
Tue Aug 9 16:37:44 EDT 2016


On Tue, Aug 9, 2016 at 2:59 PM Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Aug 10, 2016 at 4:51 AM, Michael Selik <michael.selik at gmail.com>
> wrote:
> > "File-like" is a good example. Rather than go through the frustration of
> a
> > formal definition for what is file-like, stay productive and flexible
> with
> > duck typing. Objects that don't have the appropriate methods or
> attributes
> > will cause a TypeError or AttributeError. If you're passing in the wrong
> > kind of object, you'll find out almost as soon as you write the code
> > (because you test early and often), just as you would with a statically
> > analyzed type system.
>
> It's slightly delayed; with Python, you have to actually execute the
> code path in question, whereas a static type system would detect it at
> the compilation stage. So it may depend on the quality of your
> testing. MyPy may be able to help there.
>

Depends on how long it takes to compile!
https://xkcd.com/303/
:-)



More information about the Python-list mailing list