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

Enable class constants #135

Open
gordonwatts opened this issue Mar 29, 2024 · 1 comment
Open

Enable class constants #135

gordonwatts opened this issue Mar 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@gordonwatts
Copy link
Member

class fork:
    it: int = 10

And then in a lambda expression we should allow for fork.it.

This will also change how enums are done, so this will have far reaching (probably) implications.

@gordonwatts gordonwatts added the enhancement New feature or request label Mar 29, 2024
@gordonwatts
Copy link
Member Author

Likely this code - where the isinstance for a type is called:

class _rewrite_captured_vars(ast.NodeTransformer):
    def __init__(self, cv: inspect.ClosureVars):
        self._lookup_dict: Dict[str, Any] = dict(cv.nonlocals)
        self._lookup_dict.update(cv.globals)
        self._ignore_stack = []

    def visit_Name(self, node: ast.Name) -> Any:
        if self.is_arg(node.id):
            return node

        if node.id in self._lookup_dict:
            v = self._lookup_dict[node.id]
            if not callable(v):
                # Modules should be sent on down to be dealt with by the
                # backend.
                if not isinstance(v, ModuleType):
                    legal_capture_types = [str, int, float, bool, complex, str, bytes]
                    if type(v) not in legal_capture_types:
                        raise ValueError(
                            f"Do not know how to capture data type '{type(v).__name__}' for "
                            f"variable '{node.id}' - only "
                            f"{', '.join([c.__name__ for c in legal_capture_types])} are "
                            "supported."
                        )
                    return as_literal(v)
            elif isinstance(v, type):
                assert False
        return node

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

No branches or pull requests

1 participant