Configuring an object via a dictionary

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Wed Mar 20 05:28:24 EDT 2024


On 2024-03-20 at 09:49:54 +0100,
Roel Schroeven via Python-list <python-list at python.org> wrote:

> You haven't only checked for None! You have rejected *every* falsish value,
> even though they may very well be acceptable values.

OTOH, only you can answer these questions about your situations.

Every application, every item of configuration data, is going to be a
little bit different.

What, exactly, does "missing" mean?  That there's no entry in a config
file?  That there's some sort of degenerate entry with "missing"
semantics (e.g. a line in a text file that contains the name of the
value and an equals sign, but no value)?  An empty string or list?  Are
you making your program easier for users to use, easier for testers to
test, easier for authors to write and to maintain, or something else?
What is your program allowed and not allowed to do in the face of
"missing" configuration data?

Once you've nailed down the semantics of the configuration data, then
the code usually falls out pretty quickly.  But arguing about corner
cases and failure modes without specifications is a losing battle.
Every piece of code is suspect unless you know what the inputs mean, and
what the application "should" do if the don't look like that.

Python's flexibiliry and expressiveness are double edge swords.  Use
them wisely.  :-)

Sorry for the rant.

Carry on.


More information about the Python-list mailing list