py2puml icon indicating copy to clipboard operation
py2puml copied to clipboard

support typing for typing.NamedTuple named tuples

Open lucsorel opened this issue 2 years ago • 0 comments

Classes created with collections.namedtuple carry no type annotations.

from collections import namedtuple

Function = namedtuple('Function', ['name', 'module_Path'])

py2puml would generate the following documentation:

@startuml
class Function {
  name: Any
  module_path: Any
}
@enduml

However, it is also possible to create named tuple classes with typing.NamedTuple and specify type annotations:

from typing import NamedTuple, Tuple
class Function(NamedTuple):
    '''
    Models a function (calling or being called):
    - it has a name
    - it is hosted in a module, modeled by its path as a tuple of strings
    '''
    name: str
    module_path: Tuple[str]

The expected PlantUML documentation would then be:

@startuml
class Function {
  name: str
  module_path: Tuple[str]
}
@enduml

lucsorel avatar Aug 09 '23 22:08 lucsorel