mherrmann/helium

how to use lambda in he.S(...)

Closed this issue · 1 comments

code e.g.

import helium as he

class Scaffold(object):
    @classmethod
    def exists(cls, s, below=None, to_right_of=None, above=None, to_left_of=None):        
        if isinstance(s, str) and s:
            if s.startswith(('@', '#', '.', '//')):                
                if below and to_right_of and above and to_left_of:
                    pass
                elif below and to_right_of and above:
                    pass
                elif below and to_right_of:
                    pass
                elif below:
                    ret = he.S(s, below=lambda below: he.S(below) if isinstance(below, str) else below).exists()
                ......

The expected function of the last line of code:
if below type is he.S
ret = he.S(s, below=below).exists()
if below type is str
ret = he.S(s, below=he.S(below)).exists()

But I got the following error:

image

my python environment:

F:\helloc\pipenv_proj\aaaaa>.\PIPENV_EENV_IN_PROJECT\aaaaa--EXhM6T9\Scripts\pipenv.exe graph
helium==3.0.6
  - selenium [required: ==3.141.0, installed: 3.141.0]
    - urllib3 [required: Any, installed: 1.26.4]
pipenv==2020.11.15
  - certifi [required: Any, installed: 2020.12.5]
  - pip [required: >=18.0, installed: 20.3.3]
  - setuptools [required: >=36.2.1, installed: 51.1.1]
  - virtualenv [required: Any, installed: 20.4.6]
    - appdirs [required: >=1.4.3,<2, installed: 1.4.4]
    - distlib [required: >=0.3.1,<1, installed: 0.3.1]
    - filelock [required: >=3.0.0,<4, installed: 3.0.12]
    - importlib-metadata [required: >=0.12, installed: 4.0.1]
      - typing-extensions [required: >=3.6.4, installed: 3.10.0.0]
      - zipp [required: >=0.5, installed: 3.4.1]
    - six [required: >=1.9.0,<2, installed: 1.16.0]
  - virtualenv-clone [required: >=0.2.5, installed: 0.5.4]

F:\helloc\pipenv_proj\aaaaa>

change

ret = he.S(s, below=lambda below: he.S(below) if isinstance(below, str) else below).exists()

to

ret = he.S(s, below=(lambda x: he.S(x) if isinstance(x, str) else x)(below)).exists()

it's ok