Skip to content

Improve instantiate handling of callable _target_ kwarg - #1915

Merged
Jasha10 merged 3 commits into
hydra-ecosystem:mainfrom
Jasha10:closes1914
Dec 15, 2021
Merged

Jasha10 merged 3 commits into
hydra-ecosystem:mainfrom
Jasha10:closes1914

Conversation

@Jasha10

@Jasha10 Jasha10 commented Dec 3, 2021 •

Copy link
Copy Markdown
Contributor

This PR closes #1914.

Commits

  • 90468cb: add failing test

    As of this commit, the following fails:

    pytest tests/instantiate -k 'test_instantiate_with_callable_target_keyword[instantiate2-nested]'
    
  • 1122135: patch _convert_target_to_string

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 3, 2021
Comment on lines 70 to 74
def _convert_target_to_string(t: Any) -> Any:
if isinstance(t, type):
return f"{t.__module__}.{t.__name__}"
elif callable(t):
if callable(t):
return f"{t.__module__}.{t.__qualname__}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to PEP 3155 it is appropriate to look up __qualname__ on any function or class.

@Jasha10
Jasha10 marked this pull request as ready for review December 4, 2021 11:27
@Jasha10
Jasha10 requested review from jieru-hu and pixelb December 4, 2021 11:27
As of this commit, the following fails:
```
pytest tests/instantiate -k 'test_instantiate_with_callable_target_keyword[instantiate2-nested]'
```
@Jasha10

Jasha10 commented Dec 14, 2021

Copy link
Copy Markdown
Contributor Author

Rebased against main to resolve merge conflict.

@Jasha10
Jasha10 merged commit ea9974f into hydra-ecosystem:main Dec 15, 2021
@Jasha10
Jasha10 deleted the closes1914 branch December 15, 2021 03:30
MattiasDC pushed a commit to MattiasDC/hydra that referenced this pull request Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing callable as instantiate _target_ fails for nested classes

3 participants