Skip to content

Bad performance with TypedDicts and unions #7617

@roganov

Description

@roganov

Describe the bug
Pyright takes 10 seconds to type-check the code below, while for Mypy it's 0.4 seconds. This issue comes from #7612.

Code or Screenshots
The repro could probably be smaller, I'm sorry for this. Note that the more

x: NodeFile
y: Node = x

I add, the slower it becomes.

import typing


class NodeFile(typing.TypedDict, total=False):
    name: typing.Literal["FILE"]


class NodeDocument(typing.TypedDict, total=False):
    name: typing.Literal["DOCUMENTDEF"]
    children: list[typing.Union['NodeField', 'NodeGroup', 'NodeValidation', 'NodeFormat', 'NodeEnv', 'NodePreValidation', 'NodeImports']]


class NodeGroup(typing.TypedDict, total=False):
    name: typing.Literal["GROUPDEF"]
    children: list[typing.Union['NodeField', 'NodeGroup', 'NodeValidation', 'NodeHelp', 'NodeEnv', 'NodePreValidation']]


class NodeField(typing.TypedDict, total=False):
    name: typing.Literal["FIELDDEF"]
    children: list[typing.Union['NodeValidation', 'NodeHelp', 'NodeFormat']]


class NodeJava(typing.TypedDict, total=False):
    name: typing.Literal["java"]
    text: str


class NodeFieldFormat(typing.TypedDict, total=False):
    name: typing.Literal["FIELDFMT"]
    text: str


class NodeValidation(typing.TypedDict, total=False):
    name: typing.Literal["VALIDATION"]
    children: list['NodeJava']


class NodeImports(typing.TypedDict, total=False):
    name: typing.Literal["IMPORTS"]
    text: str


class NodeFormat(typing.TypedDict, total=False):
    name: typing.Literal["FORMAT"]
    children: list[typing.Union['NodeDelimiter', 'NodeFieldFormat']]


class NodePreValidation(typing.TypedDict, total=False):
    name: typing.Literal["PREVALIDATION"]
    children: list['NodeJava']


class NodeHelp(typing.TypedDict, total=False):
    name: typing.Literal["HELP"]
    text: str


class NodeEnv(typing.TypedDict, total=False):
    name: typing.Literal["ENVIRONMENT"]
    children: list['NodeJava']


class NodeDelimiter(typing.TypedDict, total=False):
    name: typing.Literal["DELIMITER"]
    text: str


Node = typing.Union['NodeFile', 'NodeDocument', 'NodeGroup', 'NodeField', 'NodeJava', 'NodeFieldFormat', 'NodeValidation', 'NodeImports', 'NodeFormat', 'NodePreValidation', 'NodeHelp', 'NodeEnv', 'NodeDelimiter']

x: NodeFile
y: Node = x

x: NodeFile
y: Node = x

x: NodeFile
y: Node = x

x: NodeFile
y: Node = x

x: NodeFile
y: Node = x

VS Code extension or command-line
Command line, 1.1.357

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions