damogranlabs / classy_blocks

Python classes for easier creation of OpenFOAM's blockMesh dictionaries.
MIT License
126 stars 35 forks source link

Relations introspection in chop #33

Closed schperplata closed 1 year ago

schperplata commented 1 year ago

First step, just to remove problematic module introspection in [_src/classyblocks/chop.py].(https://github.com/damogranlabs/classy_blocks/blob/852c920b2628f41c4d0040c18131df7abee5e5d3/src/classy_blocks/grading/chop.py#L38)

With this approach, user can still access calculation functions, but other modules can fetch a list of calculation functions via specific getter, that is relations.get_calculation_functions(). Furthermore, one construct all chop relation classes with staticmethod: chop.ChopRelation.get_possible_combinations().

This is just a pre-condition to enable further assert refactoring. What do u say?

FranzBangar commented 1 year ago

If inspect.getmembers() is that bad it could be ditched entirely; by assembling relation function name first (all possible combinations), then checking if it exists in the module. This way other functions that would reside in that module wouldn't have any effect. It's not something I'd do, though.

schperplata commented 1 year ago

I don't think inspect-ion it is that bad, and your solution still involves some kind of inspection. And maybe we don't need to solve this right now, as it doesn't really hurt (yet) and as you said these functions are not really heavily used by other users. The main issue this PR solves is the issue with classy_blocks/src/classy_blocks/grading/chop.py module-scope (global) variable.