Skip to content

Commit

Permalink
[Python] Support annotations on transformation functions (#1298)
Browse files Browse the repository at this point in the history
Replace use of the deprecated `inspect.getargspec` with `inspect.getfullargspec`, which works when there are type annotations on the function parameters.
  • Loading branch information
justinvp committed Sep 9, 2020
1 parent d58aebf commit 304d138
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Improvements

- Update Go Helm v3 to use native client. (https://github.com/pulumi/pulumi-kubernetes/pull/1296)
- Python: Allow type annotations on transformation functions. (https://github.com/pulumi/pulumi-kubernetes/pull/1298)

## 2.5.1 (September 2, 2020)

Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/gen/python-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json
import warnings
from copy import copy
from glob import glob
from inspect import getargspec
from inspect import getfullargspec
from typing import Any, Callable, Dict, List, Optional

import pulumi
Expand Down Expand Up @@ -420,7 +420,7 @@ def _parse_yaml_object(
# Allow users to change API objects before any validation.
if transformations is not None:
for t in transformations:
if len(getargspec(t)[0]) == 2:
if len(getfullargspec(t)[0]) == 2:
t(obj, opts)
else:
t(obj)
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/pulumi_kubernetes/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
from copy import copy
from glob import glob
from inspect import getargspec
from inspect import getfullargspec
from typing import Any, Callable, Dict, List, Optional

import pulumi
Expand Down Expand Up @@ -420,7 +420,7 @@ def _parse_yaml_object(
# Allow users to change API objects before any validation.
if transformations is not None:
for t in transformations:
if len(getargspec(t)[0]) == 2:
if len(getfullargspec(t)[0]) == 2:
t(obj, opts)
else:
t(obj)
Expand Down
4 changes: 3 additions & 1 deletion tests/sdk/python/kustomize/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import pulumi_kubernetes as k8s

from typing import Any

ns = k8s.core.v1.Namespace("ns")


def set_namespace(namespace):
def f(obj):
def f(obj: Any):
if "metadata" in obj:
obj["metadata"]["namespace"] = namespace.metadata["name"]
else:
Expand Down

0 comments on commit 304d138

Please sign in to comment.