py2puml icon indicating copy to clipboard operation
py2puml copied to clipboard

support optional typing

Open lucsorel opened this issue 2 years ago • 1 comments

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 avatar Aug 04 '23 16:08 lucsorel