sacred icon indicating copy to clipboard operation
sacred copied to clipboard

Sacred dislikes return type hint in config

Open vnmabus opened this issue 3 years ago • 5 comments

I have a config function with a return type hint, like that:

@ex.config
def config() -> None:
    """Experiment config."""
    ...

It seems that Sacred is trying to match this against an overly restrictive regex, and it gives an assert error:

Traceback (most recent call last):
  File "/home/carlos/git/pytorch_congealing/main.py", line 11, in <module>
    def config() -> None:
  File "/home/carlos/Programas/Utilidades/Lenguajes/miniconda3/envs/fda/lib/python3.7/site-packages/sacred/ingredient.py", line 162, in config
    self.configurations.append(ConfigScope(function))
  File "/home/carlos/Programas/Utilidades/Lenguajes/miniconda3/envs/fda/lib/python3.7/site-packages/sacred/config/config_scope.py", line 26, in __init__
    self._body_code = get_function_body_code(func)
  File "/home/carlos/Programas/Utilidades/Lenguajes/miniconda3/envs/fda/lib/python3.7/site-packages/sacred/config/config_scope.py", line 149, in get_function_body_code
    func_body, line_offset = get_function_body(func)
  File "/home/carlos/Programas/Utilidades/Lenguajes/miniconda3/envs/fda/lib/python3.7/site-packages/sacred/config/config_scope.py", line 107, in get_function_body
    assert defs
AssertionError

vnmabus avatar Apr 26 '21 10:04 vnmabus

That's a known bug (#622), the config scopes don't support anything behind the function definition (like type annotations and comments). During that time it was discussed to rework the configuration (#664). This rewrite never happened, so I'm currently open to modifications to the regex.

thequilo avatar Apr 26 '21 12:04 thequilo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 06 '21 20:09 stale[bot]

Please, don't close unresolved issues. It is disrespectful to people that report them. I hate stale bots for that reason. Issues should only be closed if solved or if the original author doesn't answer questions for further clarification.

vnmabus avatar Apr 17 '22 07:04 vnmabus

I was also quite surprised that the stale bot closed a whole batch of issues at once. It didn't close any issues for a long time now.

@vnmabus are you willing to look into the issue and prepare a PR for it?

thequilo avatar Apr 19 '22 12:04 thequilo

I am busy right now, but I can try to fix the regex when I have time. However the whole regex approximation seems too fragile, and probably it will be better to just use the ast module instead.

vnmabus avatar Apr 19 '22 12:04 vnmabus