| 30 | |
| 31 | @staticmethod |
| 32 | def pyentry(type, args, pyname, docs): |
| 33 | pyargs = ', '.join(a.to_python() for a in args) |
| 34 | start = f'def {pyname}({pyargs}):\n' |
| 35 | hargs = args if len(args) > 0 and args[0].name != 'self' else args[1:] |
| 36 | mypy_hint = ', '.join(a.type.to_python() for a in hargs) |
| 37 | mypy_hint = f'# type: ({mypy_hint}) -> {type.to_python()}' |
| 38 | doc_hint = '' |
| 39 | for a in args: |
| 40 | doc_hint += f':type {a.name}: {a.type.to_python()}\n' |
| 41 | doc_hint += f':rtype: {type.to_python()}\n' |
| 42 | asserts = '' |
| 43 | for arg in args: |
| 44 | if arg.name == 'self': |
| 45 | continue |
| 46 | asserts += f'assert type({arg.name}) is {arg.type.to_python()}, "incorrect type of arg {arg.name}: should be {arg.type.to_python()}, is {{}}".format(type({arg.name}))\n' |
| 47 | |
| 48 | docs = s(f"{mypy_hint}\n'''{docs}\n{doc_hint}'''\n{asserts}\n", indent=4) |
| 49 | return start + docs |
| 50 | |
| 51 | def to_swig(self): |
| 52 | result = s(f'''\ |