I have a two-line code like this:
if validated_data.get('is_shipped') == False: # 管理员取消了发货,则把物流信息删掉
validated_data.update(logistics_company=None, logistics_tracking_no=None)
I am using Pycharm and the PEP8 check is on. So there is an underline below validated_data.get('is_shipped') == False which shows me Expression can be simplified. Replace boolean expression with ``not validated_data.get('is_shipped')`` . But, the truth is, I only want to run code in if statement when is_shipped is explicitly passed as False, and not when is_shipped is None. So, how can I handle this PEP8 check warning?
You hit the solution in your question: use the explicit
isoperator:This makes your condition an explicit identity, rather than the "truthy" boolean evaluation.