Merge branch 'master' into evan/auto

This commit is contained in:
Evan Boyle 2020-08-28 08:48:08 -07:00 committed by GitHub
commit ed2e5c6680
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 7 deletions

View file

@ -2,9 +2,16 @@ CHANGELOG
=========
## HEAD (Unreleased)
Alpha version of the Automation API for Go
- Alpha version of the Automation API for Go
[#4977](https://github.com/pulumi/pulumi/pull/4977)
## 2.9.1 (2020-08-127
- Python SDK: Avoid raising an error when an output has a type annotation of Any
and the value is a list or dict.
[#5238](https://github.com/pulumi/pulumi/pull/5238)
## 2.9.0 (2020-08-19)
- Fix support for CheckFailures in Python Dynamic Providers

View file

@ -1018,9 +1018,9 @@ func (mod *modContext) genNamespace(w io.Writer, ns *namespace, input bool, leve
sort.Slice(ns.children, func(i, j int) bool {
return ns.children[i].name < ns.children[j].name
})
for i, ns := range ns.children {
fmt.Fprintf(w, "%sexport namespace %s {\n", indent, ns.name)
mod.genNamespace(w, ns, input, level+1)
for i, child := range ns.children {
fmt.Fprintf(w, "%sexport namespace %s {\n", indent, child.name)
mod.genNamespace(w, child, input, level+1)
fmt.Fprintf(w, "%s}\n", indent)
if i != len(ns.children)-1 {
fmt.Fprintf(w, "\n")

View file

@ -719,7 +719,7 @@ func (mod *modContext) genResource(res *schema.Resource) (string, error) {
}
// Now generate an initializer with arguments for all input properties.
fmt.Fprintf(w, " def __init__(__self__,\n")
fmt.Fprintf(w, " resource_name,\n")
fmt.Fprintf(w, " resource_name: str,\n")
fmt.Fprintf(w, " opts: Optional[pulumi.ResourceOptions] = None")
// If there's an argument type, emit it.
@ -902,7 +902,7 @@ func (mod *modContext) genResource(res *schema.Resource) (string, error) {
} else {
fmt.Fprintf(w, " @pulumi.getter(name=%q)\n", prop.Name)
}
fmt.Fprintf(w, " def %s(self) -> %s:\n", pname, ty)
fmt.Fprintf(w, " def %s(self) -> pulumi.Output[%s]:\n", pname, ty)
if prop.Comment != "" {
printComment(w, prop.Comment, " ")
}

View file

@ -399,6 +399,11 @@ def translate_output_properties(output: Any,
# Unwrap optional types.
typ = _types.unwrap_optional_type(typ) if typ else typ
# If the typ is Any, set it to None to treat it as if we don't have any type information,
# to avoid raising errors about unexpected types, since it could be any type.
if typ is Any:
typ = None
if isinstance(output, dict):
# Function called to lookup a type for a given key.
# The default always returns None.

View file

@ -13,7 +13,7 @@
# limitations under the License.
import unittest
from typing import Dict, List, Optional
from typing import Any, Dict, List, Mapping, Optional
from pulumi.runtime import rpc
import pulumi
@ -326,6 +326,15 @@ class InvalidTypeDeclaredOptionalListOptionalStr(dict):
...
@pulumi.output_type
class OutputTypeWithAny(dict):
value_dict: Any
value_list: Any
value_dict_dict: Mapping[str, Any]
value_list_list: List[Any]
value_str: Any
class TranslateOutputPropertiesTests(unittest.TestCase):
def test_translate(self):
output = {
@ -550,3 +559,19 @@ class TranslateOutputPropertiesTests(unittest.TestCase):
for output in outputs:
with self.assertRaises(AssertionError):
rpc.translate_output_properties(output, translate_output_property, typ)
def test_any(self):
output = {
"value_dict": {"hello": "world"},
"value_list": ["hello"],
"value_dict_dict": {"value": {"hello": "world"}},
"value_list_list": [["hello"]],
"value_str": "hello",
}
result = rpc.translate_output_properties(output, translate_output_property, OutputTypeWithAny)
self.assertIsInstance(result, OutputTypeWithAny)
self.assertEqual({"hello": "world"}, result.value_dict)
self.assertEqual(["hello"], result.value_list)
self.assertEqual({"value": {"hello": "world"}}, result.value_dict_dict)
self.assertEqual([["hello"]], result.value_list_list)
self.assertEqual("hello", result.value_str)