loader: Fix loading grains with annotations#60285
Merged
Ch3LL merged 1 commit intosaltstack:masterfrom Oct 11, 2021
Merged
Conversation
cfeeab3 to
ed944ab
Compare
bdrung
added a commit
to bdrung/salt
that referenced
this pull request
Jun 1, 2021
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Forwarded: saltstack#60285
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Ch3LL
suggested changes
Jun 1, 2021
Contributor
Ch3LL
left a comment
There was a problem hiding this comment.
Needs a changelog and a test case to ensure we don't regress the ability to use custom grains with annotations in the future.
ed944ab to
568b63f
Compare
Contributor
Author
|
Added a changelog entry and test cases to prevent regressions. |
Ch3LL
previously approved these changes
Jun 2, 2021
s0undt3ch
approved these changes
Sep 15, 2021
s0undt3ch
suggested changes
Sep 15, 2021
Contributor
s0undt3ch
left a comment
There was a problem hiding this comment.
This PR has conflicts that need to be solved.
568b63f to
15d0cb3
Compare
Contributor
Author
|
Rebased. |
b72d9e7 to
d92ed37
Compare
s0undt3ch
previously approved these changes
Sep 18, 2021
Contributor
|
ping @bdrung I don't seem to have permissions to update the branch on your PR. We recently fixed the mac and debian test issues you are seeing, would you mind rebasing your branch again. |
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
d92ed37 to
80e471f
Compare
Contributor
Author
|
Rebased. |
Ch3LL
approved these changes
Oct 11, 2021
bdrung
added a commit
to bdrung/salt
that referenced
this pull request
Oct 13, 2021
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Forwarded: saltstack#60285
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
bdrung
added a commit
to bdrung/salt
that referenced
this pull request
Oct 14, 2021
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Forwarded: saltstack#60285
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
bdrung
added a commit
to bdrung/salt
that referenced
this pull request
Apr 15, 2022
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Forwarded: saltstack#60285
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
bdrung
added a commit
to bdrung/salt
that referenced
this pull request
Apr 16, 2022
If custom grain modules use annotations, salt will fail to load them.
Example grain:
```
from typing import Dict
def example_grain() -> Dict[str, str]:
return {"example": "42"}
```
`salt-call grains.items` will print this exception:
```
Failed to load grains defined in grain file ... in function <...>, error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/loader.py", line 847, in grains
parameters = salt.utils.args.get_function_argspec(funcs[key]).args
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 271, in get_function_argspec
aspec = _getargspec(func)
File "/usr/lib/python3/dist-packages/salt/utils/args.py", line 40, in _getargspec
"Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
```
Python recommends to use `inspect.signature` instead of
`inspect.getfullargspec` (which is only needs to maintain compatibility with
the Python 2 `inspect` module API). Since salt only supports Python 3, drop
using the wrapper function `get_function_argspec` and use `inspect.signature`
directly.
Forwarded: saltstack#60285
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If custom grain modules use annotations, salt will fail to load them. Example grain:
salt-call grains.itemswill print this exception:Python recommends to use
inspect.signatureinstead ofinspect.getfullargspec(which is only needs to maintain compatibility with the Python 2inspectmodule API). Since salt only supports Python 3, drop using the wrapper functionget_function_argspecand useinspect.signaturedirectly.