python / python/mypy

Support conditional definitions in dataclasses, etc.

Open
#21,316 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

Support Python version and other checks that can be evaluated statically in bodies of dataclasses, named tuples, and other cases discussed in https://github.com/python/typing-council/issues/58.

Example that should work:

import sys

from typing import NamedTuple

class NT(NamedTuple):
    x: int
    if sys.version_info >= (3, 12):
        y: str

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the example and the linked typing-council discussion, then inspect mypy's handling of dataclasses and NamedTuple definitions. Identify how statically evaluable Python-version checks are currently treated. Done means the example type-checks correctly and the agreed conditional-definition cases are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.