Skip to content

[Feature Request] Python codegen: docstrings and attribute access so item docs show on hover #1215

Closed

Description

@jhoogstraat

Description

Make the module generated by @generatePythonEnv show each item's description, @docs() links and source in the editor on hover, the way the generated TypeScript types do through JSDoc.

Today the Python generator writes the description and docs as # comments next to each TypedDict field:

class Env(TypedDict):
    # Secret key of the Langfuse project that receives traces
    # Docs: https://langfuse.com/docs/observability/sdk/python/setup | Langfuse Python SDK setup
    LANGFUSE_SECRET_KEY: str

Python tooling ignores comments, so none of this reaches the developer while they write env["LANGFUSE_SECRET_KEY"].

Motivation

We moved a Python monorepo (uv workspace) to varlock with @generatePythonEnv and wrote descriptions and @docs() links for every item. In the TypeScript integration that work shows up on hover. In Python it is only visible if you open the generated file.

I checked what the pyright language server (1.1.414, the engine behind Pylance) returns for a few variants of the generated module:

Generated code Hover where the value is used Hover on the declaration Go to definition from the usage
TypedDict field with # comments (current) nothing type only nothing
TypedDict field with an attribute docstring nothing docstring rendered as Markdown nothing
Protocol property with a docstring, used as env.LANGFUSE_SECRET_KEY docstring rendered as Markdown docstring rendered as Markdown jumps to the declaration

Pyright offers no hover or go-to-definition on TypedDict key strings at all. Key completion inside env["…"] shows only the type. So docstrings fix the declaration site, but only attribute access gets documentation where values are actually read.

Proposed Solution

  1. Emit attribute docstrings instead of # comments on the TypedDict fields, with the description, the @docs() links as Markdown links, and the schema file that declares the item, which matters once a monorepo imports schemas from several packages. This is a small change to the generator and immediately helps anyone reading or hovering the declaration.

    class Env(TypedDict):
        LANGFUSE_SECRET_KEY: str
        """Secret key of the Langfuse project that receives traces
    
        Docs: [Langfuse Python SDK setup](https://langfuse.com/docs/observability/sdk/python/setup)
        Source: packages/common/.env.schema
        """
  2. Optionally generate an attribute-access type, such as a Protocol with one documented read-only property per item, so that env.LANGFUSE_SECRET_KEY carries the documentation where it is used. Add native Python integration #952 already gives the native ENV object attribute access at runtime, so the generated module could type that path too, for example @generatePythonEnv(path=env.py, access=attributes), or emitting both shapes. This is the variant that showed full hover and go-to-definition in my test:

    class Env(Protocol):
        @property
        def LANGFUSE_SECRET_KEY(self) -> str:
            """Secret key of the Langfuse project that receives traces
    
            Docs: [Langfuse Python SDK setup](https://langfuse.com/docs/observability/sdk/python/setup)
            Source: packages/common/.env.schema
            """
            ...

@deprecated could map to typing_extensions.deprecated / warnings.deprecated (3.13+) on the property, which editors render as strikethrough. That's the Python counterpart of the JSDoc @deprecated tag from #644.

Alternatives

  • Keep the TypedDict and only switch to docstrings (step 1). That's cheap and an improvement, but in pyright/Pylance it doesn't show the documentation where values are read.
  • Wrap the generated Env by hand in our own typed accessor class. That duplicates every item and drifts from the schema, which is what codegen is meant to avoid.

Additional Information

Activity

  1. pullfrog commented on Oct 13, 2026

    @pullfrog
    Contributor
  2. theoephraim commented on Oct 13, 2026

    @theoephraim
    Member

    thanks for flagging this. Happy to change the shape for better intellisense. Will dig in a bit to see what the best shape is.

  3. github-actions commented on Oct 13, 2026

    @github-actions
    Contributor

    ✅ A fix has been merged to main in #1219 and will ship in the next release. GitHub auto-closed this issue on merge, but the change isn't published yet.

  4. jhoogstraat commented on Oct 30, 2026

    @jhoogstraat
    Author

    Thanks for this! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions