A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-June/120658.html below:

[Python-Dev] A Desperate Plea For Introspection (aka: BDFAP Needed)

[Python-Dev] A Desperate Plea For Introspection (aka: BDFAP Needed) [Python-Dev] A Desperate Plea For Introspection (aka: BDFAP Needed)Christian Heimes lists at cheimes.de
Fri Jun 22 21:25:14 CEST 2012
Am 22.06.2012 21:10, schrieb Yury Selivanov:
> I think that if a function lacks an annotation, that should be reflected
> in the same way for its signature.
> 
> Currently:
> 
>     if hasattr(signature, 'return_annotation'):
> 
> If we use Signature.empty:
> 
>     if signature.return_annotation is not signature.empty:
> 
> So (in my humble opinion) it doesn't simplify things too much.
> And also you can use 'try .. except AttributeError .. else' blocks,
> which make code even more readable.

The second form has two benefits:

 * you get a sensible error message when you mistype the name of the
attribute. hasattr(signature, 'return_annotatoin') is clearly an error,
hard to notice with the naked eye and passes silently.

* modern Python IDEs have code completion. "signature.re<TAB> is not
signature.em<TAB>" safes key strokes.

Christian

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4