I'm trying to create a Protocol for type hinting a...
# python
a
I'm trying to create a Protocol for type hinting any azure-native Pulumi Resource that adhere to a Protocol I've been successful in typing: • Instances having
id
,
name
,
location
etc. properties present to get rid of using
Any
with
isinstance()
&
hasattr()
checks • Pulumi Resource Class Objects – which I use to retreive metadata like naming restrictions, public/private DNS information, for a given Resource Class The only problem I haven't been able to overcome is to hint that the type is a subclass or instance of
pulumi.Resource
/
pulumi.CustomResource
Maybe this isn't possible without an Intersection type which isn't yet available in Python? But thought I'd ask here if someone has been able to figure out a workaround or a better alternative way to achieve this?
pulumi_python_typing_shenanigans.py
h
looking at https://typing.readthedocs.io/en/latest/spec/protocol.html#subtyping-relationships-with-other-types , I think you need to define a separate protocol for pulumi resources
• A protocol is never a subtype of a concrete type.
also, that
T
should be
typing.Self