lucsorel / py2puml

Generate PlantUML class diagrams to document your Python application.
https://pypi.org/project/py2puml/
MIT License
225 stars 35 forks source link

support optional typing #50

Open lucsorel opened 1 year ago

lucsorel commented 1 year ago

py2puml fails to inspect a dataclass using Optional as follows:

from dataclasses import dataclass
from typing import Optional
@dataclass
class MyData:
  data: Optional[bool]

ValueError: Could not resolve type typing.Union in module <module 'tests.modules.withoptional' from '.../py2puml/tests/modules/withoptional.py'>: it needs to be imported explicitly.

It is because Optional[bool] is dynamically converted into Union[bool, None] without adding both typing.Union and typing.Nonetype in the module wrapped by the ModuleResolver.

lucsorel commented 1 year ago

This issue was first revealed in https://github.com/lucsorel/py2puml/issues/45#issuecomment-1653282075