Skip to content

python: Test optional values against None explicitly - #297

Closed
daandemeyer wants to merge 1 commit into
amutable-systems:mainfrom
daandemeyer:push-puoprpwmrnxq
Closed

daandemeyer wants to merge 1 commit into
amutable-systems:mainfrom
daandemeyer:push-puoprpwmrnxq

Conversation

@daandemeyer

Copy link
Copy Markdown
Member

ty 0.0.86 reports every truthiness test of an optional str, bytes, int or
list as an error. A truthiness test treats None and an empty value the same
way. Compare against None where the value is never empty. Give environment
lookups an empty default where an empty variable means unset. Take the rpm
driver's languages and cache seeds as a sequence that defaults to empty,
because an empty list already meant the same as None there.

Signed-off-by: Daan De Meyer daan@amutable.com

ty 0.0.86 reports every truthiness test of an optional str, bytes, int or
list as an error. A truthiness test treats None and an empty value the same
way. Compare against None where the value is never empty. Give environment
lookups an empty default where an empty variable means unset. Take the rpm
driver's languages and cache seeds as a sequence that defaults to empty,
because an empty list already meant the same as None there.

Signed-off-by: Daan De Meyer <daan@amutable.com>
Comment thread bin/cache_shim.py
"""
named = _digest(str(store.resolve()))
runtime = os.environ.get("XDG_RUNTIME_DIR")
runtime = os.environ.get("XDG_RUNTIME_DIR", "")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR: That's the kind of "pointless noise" why I disabled that new rule in #293. a default of "" for a directory does not make any sense semantically, so a clean fix would have to do is not None rather.

The "fals-y" concept is pretty deeply woven into Python, so I find the new rule overzealous for most purposes.

Comment thread bin/tine.py
subcommand=subcommand,
# The flag's own fallback, which Buck honors wherever the flag may appear.
isolation=isolation or os.environ.get("BUCK_ISOLATION_DIR"),
isolation=isolation or os.environ.get("BUCK_ISOLATION_DIR") or None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also stupid noise IMHO. .get() already returns None as a default.

@daandemeyer

Copy link
Copy Markdown
Member Author

Sure, I opened two new PRs for the two findings that are actually bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants