Flagging 'None' string as an issue in Python

Hi Team,

I was wondering if it makes sense to flag assigning “None” string to variables in Python. This is a fairly common mistake by junior developers where “None” string gets used for API models or for storage in DBs.

This is almost always a bad practice. It should be None instead so that API frameworks can correctly return it as null on conversion to JSON.

Thanks

Hello @SAURABH-CARDANO,

Thanks a lot for your post and your rule proposal. It’s always appreciated to have improvement suggestions from a Sonar user!

I think this is a sound rule. I’ve created a Rule Proposal ticket. The process is now that we will refine the rule (to write it in a Sonar way). Then we will have a vote to ensure that the rule makes sense to several Sonar developers. We can then proceed with the rule implementation.

We will follow this process as soon as we have a related sprint, like core Python language rules or something similar.

Thank you again for your post,

2 Likes