Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link to python in some way for arkouda #15

Open
mhmerrill opened this issue Jun 15, 2022 · 5 comments
Open

link to python in some way for arkouda #15

mhmerrill opened this issue Jun 15, 2022 · 5 comments

Comments

@mhmerrill
Copy link
Owner

investigate a flow which looks like:

  1. decorator fetches source
  2. builds ast
  3. uses ast to write scheme/lisp expr
  4. use arguments and annotations to write linkage
  5. which can feed LisExpr linked into Arkouda.
@mhmerrill
Copy link
Owner Author

mhmerrill commented Jun 15, 2022

decorator example:

https://realpython.com/primer-on-python-decorators/#syntactic-sugar

def my_decorator(func):
    def wrapper():
        print("Something is happening before the function is called.")
        func()
        print("Something is happening after the function is called.")
    return wrapper

@my_decorator
def say_whee():
    print("Whee!")

@mhmerrill
Copy link
Owner Author

mhmerrill commented Jun 15, 2022

get source code example:

https://www.adamsmith.haus/python/answers/how-to-get-the-source-code-of-a-function-in-python

def f():
   x = 1 + 2
   return(x)

source_code = inspect.getsource(f)

print(source_code)
OUTPUT
def f():
   x = 1 + 2
   return(x)

@mhmerrill
Copy link
Owner Author

mhmerrill commented Jun 15, 2022

parse the source_code to get ast:

https://greentreesnakes.readthedocs.io/en/latest/tofrom.html

>>> tree = ast.parse("print('hello world')")
>>> tree
<_ast.Module object at 0x9e3df6c>
>>> exec(compile(tree, filename="<ast>", mode="exec"))
hello world

@mhmerrill
Copy link
Owner Author

mhmerrill commented Jun 15, 2022

annotations:

https://realpython.com/lessons/annotations/#:~:text=Annotations%20were%20introduced%20in%20Python,D.

>>> import math

>>> def circumference(radius: float) -> float:
...     return 2 * math.pi * radius
...
...
>>> circumference.__annotations__
{'radius': <class 'float'>, 'return': <class 'float'>}
>>> circumference(1.23)
7.728317927830891

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

No branches or pull requests

1 participant