Fine-grained: Inconsistent behavior for nested NewType

Open
#4,615 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start with the fine-grained incremental mode test case testRefreshNestedNewType and run it through both increments described for a.py and b.py. Compare the first and second outputs for the nested NewType declarations; done means both runs produce identical errors for each example.

Written by the indexing model from the issue text.

Description

bug priority-2-low topic-fine-grained-incremental

The output of the second increment of this fine-grained incremental mode test case doesn't generate an error, even though nothing relevant has changed:

[case testRefreshNestedNewType]
import a
[file a.py]
from typing import Union, NewType
import b

def f(self) -> None:
    X = NewType('X', A)

A = str
[file b.py]
y = 0
[file b.py.2]
y = ''
[out]

Here's the output:

a.py:5: error: Argument 2 to NewType(...) must be subclassable (got A?)
==

The expected output would be identical for both runs.

The output from the first and second runs also does not match for this slightly different test case:

[case testRefreshNestedNewType]
import a
[file a.py]
from typing import Union, NewType
import b

def f(self) -> None:
    X = NewType('X', A)

A = Union[int, str]

[file b.py]
y = 0
[file b.py.2]
y = ''
[out]

Here's the output (again expected to be identical):

a.py:5: error: Argument 2 to NewType(...) must be subclassable (got A?)
==
a.py:5: error: Argument 2 to NewType(...) must be subclassable (got "Union[int, str]")

It looks like forward references within NewType declarations behave inconsistently.

Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

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.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.