{"id":81,"date":"2011-05-19T08:25:00","date_gmt":"2011-05-19T08:25:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=81"},"modified":"2011-05-19T08:25:00","modified_gmt":"2011-05-19T08:25:00","slug":"is-not-none-maybe-something","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=81","title":{"rendered":"Is &#8220;not None&#8221; maybe &#8220;Something&#8221;?"},"content":{"rendered":"<p>I just had a funny thought. In Python you can write:<\/p>\n<pre>if not someObject is None:<br \/>    someObject.doSomething()<br \/>else:<br \/>    print \"someObject is None!\"<br \/><\/pre>\n<p>This reads a bit strange. So what if you could alias &#8220;not &#8230; is None&#8221; to &#8220;&#8230; is Something&#8221;?<\/p>\n<pre>if someObject is Something:<br \/>    someObject.doSomething()<br \/>else:<br \/>    print \"someObject is None!\"<br \/><\/pre>\n<p><\/p>\n<div>It seems that this idea was <a href=\"http:\/\/mail.python.org\/pipermail\/python-dev\/2003-December\/041318.html\">thought of<\/a> almost eight years ago already. This lead to some PEP 0326, which got rejected. If Python were a macro or functional language, you could probably hack something up to do the same thing, but it does not work like that:<\/div>\n<p><\/p>\n<pre>>>> Something = not None<br \/>>>> Something<br \/>True<br \/>>>> A = [1,2,3]<br \/>>>> if A is Something:<br \/>...     print \"This is something\"<br \/>... else:<br \/>...     print \"This is nothing\"<br \/>... <br \/>This is nothing<br \/>>>> <br \/><\/pre>\n<p><\/p>\n<div>The problem here being, that &#8220;non None&#8221; is immediately evaluated to &#8220;True&#8221;, since &#8220;None&#8221; can be implicitly converted to &#8220;False&#8221; in a boolean sense. Was a funny thought, though.<\/div>\n<p><\/p>\n<div>Update: Turns out you can at least write &#8220;if someObject is not None:&#8221;, which is more readable. <\/div>\n","protected":false},"excerpt":{"rendered":"<p>I just had a funny thought. In Python you can write: if not someObject is None: someObject.doSomething()else: print &#8220;someObject is None!&#8221; This reads a bit strange. So what if you could alias &#8220;not &#8230; is None&#8221; to &#8220;&#8230; is Something&#8221;? if someObject is Something: someObject.doSomething()else: print &#8220;someObject is None!&#8221; It seems that this idea was &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=81\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Is &#8220;not None&#8221; maybe &#8220;Something&#8221;?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/81"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}