gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
765 stars 138 forks source link

Dynamic solution to formulas #328

Closed BAPCon closed 6 months ago

BAPCon commented 8 months ago

Not sure if this is a poor implementation or if it doesn't fit the intended update goals, but I'm working on a dynamic solution to the issues surrounding formulas mentioned by @mesozoic and others.

I have a WIP that allows the following to be done

Function/Formula Subclass Generation

  1. Take a CSV export from the formula playground
  2. Run the WIP script generate.py passing in the export as args.
  3. The script runs through each row from the export, identifies the type of function as well as the type for each parameter passed into the function, and serializes the current ~80 functions.
  4. The script then generates subclasses from a parent class in formulas.py that contains generic attributes/functions.
  5. This generated content is then spliced back into the actual package.

Issues:

Working on composable objects

I've got the composable aspect down conceptually, going about it in a way similar to reverse Polish notation, but I could use some guidance/suggestions regarding @mesozoic's comment:

We should be able to use operators like & and | to build complex logical conditions

I'm familiar with overriding __add__ for example, but could use some clarity on how this is ideally implemented for this project. Ke

Please critique the generation features in the WIP if they are throwing out alarm bells or if it is a noob idea in general.

mesozoic commented 8 months ago

I had not thought of using the formula playground as a source, but that's a great idea! My approach had been to scrape the text of their formula documentation, which resulted in a lot of mess that needed to be cleaned up by hand.

I realized that I'd never posted a draft PR for my branch, so I've put that up as #329. Patches or suggestions are welcome there, especially if your branch has any capabilities mine doesn't :)