Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support typing for typing.NamedTuple named tuples #54

Open
lucsorel opened this issue Aug 9, 2023 · 0 comments
Open

support typing for typing.NamedTuple named tuples #54

lucsorel opened this issue Aug 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@lucsorel
Copy link
Owner

lucsorel commented Aug 9, 2023

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 lucsorel added the enhancement New feature or request label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant