great-sunset-355
02/22/2022, 11:32 AMmypy
Code 1:
How can I cast or at least tell that output is a type Ouput[str]
and not Output[any]
?
r53_zone = aws.route53.get_zone(zone_id=SHARED_STACK_REF.require_output('hosted_zone_id'))
mypy output
Argument "zone_id" to "get_zone" has incompatible type "Output[Any]"; expected "Optional[str]"
Code 2
Why do I get an error and how to prevent that? It looks like that profile
attribute is dynamically created, correct?
ec1_provider = aws.Provider(
f"{PREFIX}-{ec1_region}", profile=aws.config.profile, region=ec1_region
)
mypy output:
__main__.py:27: error: Module has no attribute "profile"
prehistoric-activity-61023
02/22/2022, 12:25 PMmypy
doesn’t complain using # type: ignore
comment (I’d use it as a last resort)
• fix the code so it actually returns the expected types (ideal but the hardest one)pulumi.StackReference
class or create some helper methods yourself that does type assertions (get_string_output(stack_ref: pulumi.StackReference, name: pulumi.Input[str]) -> pulumi.Output[str]
). Another problem might be AWS provider that expects Optional[str]
instead of Input[str]
.profile
), I’d have to take a look but if the following code works, you might be right.profile
is declared as Optional[pulumi.Input[str]]
so it shouldn’t cause any issues).aws.config
I guess.aws_config: aws.config.vars._ExportableConfig = typing.cast(aws.config, aws.config.vars._ExportableConfig)
and instead of:
aws.config.profile
you could use:
aws_config.profile
Still, it doesn’t look good IMO 😐def aws_profile() -> str:
return aws.config.profile # type: ignore
and use it that instead of directly accessing aws.config
object