Hey everyone, I am trying to write a component lib...
# python
d
Hey everyone, I am trying to write a component library in Python and I'm up to the point of trying to install my package into a project to actually use and I'm getting the following error:
Copy code
File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/host.py", line 56, in component_provider_host  
    main(ComponentProvider(components, name, namespace, version), args)      
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/component.py", line 61, in __init__ 
    result = self.analyzer.analyze(components)         
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/analyzer.py", line 276, in analyze  
    c = self.analyze_component(component)   
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/analyzer.py", line 355, in analyze_component   
    (inputs, inputs_mapping) = self.analyze_type(args, is_component_output=False)       
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/analyzer.py", line 404, in analyze_type        
    camel_case(k): self.analyze_property(   
        ~~~~~~~~~~~~~~~~~~~~~^   
        v, 
        ^^ 
    ...<3 lines>...   
        is_component_output=is_component_output,       
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       
    )      
    ^      
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/analyzer.py", line 594, in analyze_property    
    elif is_enum(arg):
         ~~~~~~~^^^^^ 
  File "<home_dir>/venv/lib/python3.13/site-packages/pulumi/provider/experimental/analyzer.py", line 819, in is_enum  
    return issubclass(typ, Enum) 
TypeError: issubclass() arg 1 must be a class
I did some fiddling with the analyzer and I can see that the type it's bombing on is a
Mapping[str, pulumi.Input[str]]
field on one of my objects used to configure the tags on my component. I get this error when I try to install the package from a GitHub repo, but if I clone the repo locally, set up the venv and then point the
pulumi package add
command at the local installed clone then it doesn't seem to have any problems generating SDKs with no code changes on my part. Am I hitting a bug here? What types are in scope when it comes to Pulumi generating valid SDK values from type annotations? I have tried annotated types for other fields and they also seem to cause issues. Just would like to know as debugging these type issues is basically impossible without manually fiddling with the analyzer to dump out the type causing the TypeError to be thrown
m
Hey @delightful-queen-14969 does it work if types are for instance Mapping[str, str] rather than Mapping[str, pulumi.Input[str]]?
d
I just tested running
collections.abc.Mapping
through
issubclass
for every Python version since 3.9 and found something very interesting: Python 3.9 - 3.12:
Copy code
>>> issubclass(collections.abc.Mapping, Enum)
False
>>> issubclass(collections.abc.Mapping[str, str], Enum)
False
Python 3.13:
Copy code
>>> issubclass(collections.abc.Mapping, Enum)
False
>>> issubclass(collections.abc.Mapping[str, str], Enum)
Traceback (most recent call last):
  File "<python-input-17>", line 1, in <module>
    issubclass(collections.abc.Mapping[str, str], Enum)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class
Even more confusingly, the version of Python used when installing the venv locally is Python 3.13, so it's not like I was installing using an older Python version. Just checked the venv set up in the venv set up by Pulumi in
~/.pulumi/plugins
and that is also Python 3.13. The difference in behaviour between versions is interesting, though
m
So, congrats, @delightful-queen-14969. I think you may have found a bug.
Could you write it up in https://github.com/pulumi/pulumi/issues ?
d
For sure, cheers
m
I think the issue is around Python 3.13 changing how type annotations work. So that
issubclass()
raises
TypeError
. But I'm not clear why that would change for you based on local vs git.
d
Yeah, I was reluctant to log the issue immediately because I had no idea what to set as the title. Too many moving bits and I don't want to lead people down the garden path with a wrong description of what the actual cause is
🙏 1