Skip to content

Consider offering a shim import of server-prepared data #5

@frthjf

Description

@frthjf

Currently, data params that are setup in server.py are magically injected into the setup_code.py namespace. This confuses IDEs' static checks (error messages) and makes it harder to understand what's happening for both humans and code agents. I think it would be useful to provide a data proxy that can be imported instead, something like:

import inspect

class _Shim:
    def __getattr__(self, name):
        try:
            return inspect.stack()[1].frame.f_globals[name]
        except (KeyError, IndexError):
            raise AttributeError(...)

server_data = _Shim()

So that

import numpy as np

np.random.seed(seed)   # undefined name `seed`

can be rewritten as

import numpy as np
from pytest_pl_grader import server_data

np.random.seed(server_data.seed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions