ordered icon indicating copy to clipboard operation
ordered copied to clipboard

Resolve class methods from context-local variables

Open grandrew opened this issue 4 years ago • 0 comments

In this situation:

import pytest, gc
import ordered, random

__author__ = "Andrew Gree"
__copyright__ = "CriticalHop Inc."
__license__ = "MIT"


class MyVars:
    x: int
    steps: int
    def __init__(self) -> None:
        self.x = 0
        self.steps = 0

    def plus_x(self):
        self.x += 3
        self.count_steps()

    def minus_x(self):
        self.x -= 2
        self.count_steps()
    
    def count_steps(self):
        self.steps += 1

@pytest.mark.skip(reason="TODO")
def test_partial_context_oo_full():
    m = MyVars()
    m.x = 5
    with ordered.orderedcontext():
        # exit ordered context without exceptions with minimum steps
        while m.x != 12:  
            ordered.choice()()  
    assert m.x == 12
    assert m.steps == 4

we're calling choice() with no parameters. This code fails as no methods for m are generated.

A solution needed to have a logically expected behaviour:

  1. all variables explicitly used in the context are scanned for their class' methods
  2. if choice() is selecting all functions from heap then it's huge as Python always has a lot of stuff loaded. Maybe choice() must actually scan this module's globals() for functions and methods?

grandrew avatar Aug 13 '21 18:08 grandrew