KEMBAR78
Regression related type objects and no strict optional · Issue #19751 · python/mypy · GitHub
Skip to content

Regression related type objects and no strict optional #19751

@JukkaL

Description

@JukkaL

When type checking these files, there's a false positive in x.py when using a cold cache (rm -rf .mypy_cache first). This is a regression from mypy 1.17 and is a release blocker. The behavior is inconsistent between cached and uncached runs.

typ.py:

from typing import NamedTuple

NT = NamedTuple("NT", [("x", str | None)])

mod.py:

# mypy: no-strict-optional

from typ import NT

def f() -> NT:
    return NT(x='')

x.py:

import mod

# Argument "x" to "NT" has incompatible type "None"; expected "str"
a = mod.NT(x=None)

It looks like the NT parameter type gets simplified to just str from str | None when the type is used in a module with strict optional checking disabled.

This bisects to #19514 (cc @ilevkivskyi). Maybe the caching should be disabled in modules that don't use strict optional checking?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions