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

recursive_guard has become required keyword in ForwardRef._evaluate() #2235

Open
mmacpherson opened this issue Jan 30, 2025 · 3 comments · May be fixed by #2311
Open

recursive_guard has become required keyword in ForwardRef._evaluate() #2235

mmacpherson opened this issue Jan 30, 2025 · 3 comments · May be fixed by #2311

Comments

@mmacpherson
Copy link

Proximally, I was trying to use the Runner API, like so:

with Runner(my_flow.__file__, pylint=False).run(
    job_ids=["E10288"], # This is a JSONType parameter.
    max_workers=1,
) as running:
    print(f"{running.run} completed")

That throws up a:

TypeError

    This cell raised an exception: TypeError('ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'')

Which stands to reason, because in cpython recursive_guard (now) appears to be keyword-only in ForwardRef._evaluate. (And ForwardRef._evaluate is deprecated, looks like...) https://github.com/python/cpython/blob/4e47e05045b7b05c7e166bda2afd60191314e326/Lib/annotationlib.py#L180

And metaflow's vendored-in typeguard lib is calling it without the kwarg: https://github.com/Netflix/metaflow/blob/master/metaflow/_vendor/typeguard/_utils.py#L18

When I patch that line as follows, it works, in the sense that the error above disappears and my flow runs:

if sys.version_info >= (3, 10):
    from typing import get_args, get_origin

    def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any:
        # return forwardref._evaluate(memo.globals, memo.locals, frozenset())
        return forwardref._evaluate(
            memo.globals, memo.locals, recursive_guard=frozenset()
        )

It looks like this issue showed up in typeguard a few months back, and appears to have been fixed in their 4.3.0: agronholm/typeguard#466

I'd be glad to contribute a PR here, having benefited much from Metaflow. If the right change is bigger than this patch, perhaps because it entails upgrading the vendored typeguard dependency, I'm game to help, but wouldn't be offended if it's better left to someone more familiar with the codebase.

Thanks for making metaflow!

Setup

  • metaflow 2.13.7
  • python 3.12.5
@savingoyal
Copy link
Collaborator

It would be great if you can open a PR!

@mmacpherson
Copy link
Author

Glad to. To clarify, would you prefer that the PR patch this line "in the small" (with accompanying test)? Or is the appropriate path here to bump the typeguard dependency to 4.30+? Thanks.

@savingoyal
Copy link
Collaborator

it would be better to bump the typeguard dependency - we try to not change much within the vendored dependencies.

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

Successfully merging a pull request may close this issue.

2 participants