Skip to content

support typing for typing.NamedTuple named tuples #54

@lucsorel

Description

@lucsorel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions