Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

is not None problems #32

Open
shargon opened this issue Jan 26, 2018 · 4 comments
Open

is not None problems #32

shargon opened this issue Jan 26, 2018 · 4 comments

Comments

@shargon
Copy link
Member

shargon commented Jan 26, 2018

This source produce if (false) output

def Main(operation):

    if operation is not None:
        return True
    else:
        return False

As you can see, is impossible to return true in this opCode output

image

Could you check it @localhuman ?

@belane
Copy link
Member

belane commented Jan 26, 2018

if operation: could be the right python style to do it.
But you can do (and it should work):

>>> def Test(argument):
      if argument is not None:
              return True
      else:
              return False
 
>>> Test(1)
True
>>> Test(None)
False

in this case I think the appropriate would be

def Main(operation=None):
    if operation:
        return True
    else:
        return False

avm for this last example is well compiled:
avm

@brianlenz
Copy link

This code originated from the NEX neo-ico-template:

https://github.com/neonexchange/neo-ico-template/blob/master/ico_template.py#L61

I would think these three should be functionally identical:

if operation:
if operation != None:
if operation is not None:

or am I missing something?

@belane
Copy link
Member

belane commented Jan 26, 2018

Test 1 👍

def Main(operation):
    if operation:
        return True
    else:
        return False

image

Test 2 👍

def Main(operation):
    if operation != None:
        return True
    else:
        return False

image

Test 3 👎

def Main(operation):
    if operation is not None:
        return True
    else:
        return False

image

@localhuman
Copy link
Collaborator

With new version of compiler I will be interested in this!

I'll have to add a NoneTest to see and document exactly how it behaves.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants