python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.19k stars 2.78k forks source link

Inline union assigned to type alias produces error #14302

Closed tcobbs-bentley closed 1 year ago

tcobbs-bentley commented 1 year ago

Bug Report The following code produces an error when using mypy as a linter in Visual Studio Code:

Test = tuple[str, str] | str

(Using pylint as a linter, the above code does not produce an errror.)

The following (equivalent, AFAIK) code does not produce an error when using mypy as a linter:

Test = Union[tuple[str, str], str]

For reasons that aren't really clear, the following code does not produce an error (even though it seems similar to the code that produces an error):

SQLiteDescription = tuple[tuple[str, None, None, None, None, None, None], ...] | Any

For reference, the error (in Visual Studio Code) is this:

[{
    "resource": "/Users/travis/Dev/itwin/mobile-samples/cross-platform/startuptimes/startuptimes.py",
    "owner": "python",
    "code": "error",
    "severity": 8,
    "message": "Type application has too many types (1 expected)  [misc]",
    "source": "mypy",
    "startLineNumber": 23,
    "startColumn": 8,
    "endLineNumber": 23,
    "endColumn": 8
}]

(A clear and concise description of what the bug is.)

To Reproduce

  1. Install Visual Studio Code
  2. Install Microsoft's Python plugin
  3. Open a Python file.
  4. Use the Python: Select Linter command (from F1 command palette) to select mypy as the linter.
  5. Install mypy if prompted to do so.
  6. Include the following code in your Pyton file:
Test = tuple[str, str] | str

Expected Behavior

The code should be accepted by mypy.

Actual Behavior

mypy gives the following error:

Type application has too many types (1 expected)  [misc]

Your Environment

AlexWaygood commented 1 year ago

Duplicate of #11098

AlexWaygood commented 1 year ago

(It's already fixed on mypy master; the fix will be included in the next release, mypy 1.0.)

tcobbs-bentley commented 1 year ago

Sorry, I didn't search closed issues.

AlexWaygood commented 1 year ago

No worries! Follow #13685 for updates on when the next release will be coming.