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

Unexpected behavior from classdiagram class fields containing parentheses inside of brackets #5881

Open
diceroll123 opened this issue Sep 20, 2024 · 4 comments
Assignees
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@diceroll123
Copy link

diceroll123 commented Sep 20, 2024

Description

It seems that after parentheses close, anything after that is strictly put after the : for the class field.

I got this from a valid Python type annotation, https://github.com/fastapi/fastapi/blob/7c6f2f8fde68f488163376c9e92a59d46c491298/fastapi/datastructures.py#L64-L73 (see third line in my repro)

Steps to reproduce

classDiagram
    class Thing {
        + a()] blah
        + Literal[a("blah!")] blah
        + Annotated[Optional[str], Doc("The original file name.")] filename
    }
Loading

unrendered:

classDiagram
    class Thing {
        + a()] blah
        + Literal[a("blah!")] blah
        + Annotated[Optional[str], Doc("The original file name.")] filename
    }

Screenshots

No response

Code Sample

No response

Setup

  • Mermaid version:
  • Browser and Version: [Chrome, Edge, Firefox]

Suggested Solutions

No response

Additional Context

No response

@diceroll123 diceroll123 added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Sep 20, 2024
@jgreywolf
Copy link
Contributor

Since I am not sure if I am fully understanding, can you please explain what you expected to happen, vs what did happen? Also, if you could provide the exact syntax you used it will be very helpful for repro

@jgreywolf jgreywolf self-assigned this Sep 25, 2024
@diceroll123
Copy link
Author

Sure thing, my bad!

I've updated the original post with unrendered markdown of the diagram.

Given that class diagram, I expected something like the following image, which I've edited from the initial render with Inspect Element,

image

additionally, however

I am only now realizing that by these annotated types having a complete pair of parens, that they are marked as functions/methods (third compartment) rather than attributes (middle compartment).

While this Doc method (the third line in the rendered mermaid diagram) within type annotations is not (yet?) an approved part of Python, it is backward-compatible + valid syntax and is already in use, https://peps.python.org/pep-0727/


To summarize:

Syntactically correct Python class annotations which themselves execute a callable function such as filename below, due to having a pair of parens are both:

  • classified as a callable itself
  • incorrectly parsed once the parens end (as shown with the bracket on the right-hand side of the colon between the annotation and the variable name)

within a rendered mermaid diagram.

from typing import Optional, Annotated
from typing_extensions import Doc

class Thing:
    filename: Annotated[Optional[str], Doc("The original file name.")]

@jgreywolf
Copy link
Contributor

I am sorry for the LONG delay - but I am now actively working on an update to the class diagram syntax that will address this, and other, issues.

Should have something within a couple of days :)

@jgreywolf
Copy link
Contributor

Its been more than a couple of days. I am going to split this out from the large list of class diagram issues I was trying to put into one PR ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

2 participants