Skip to content

Strange error message with variable type annotation #2398

Closed
@graingert

Description

@graingert
from typing import NewType

Ticker = NewType('Ticker', str)
SecurityID = NewType('SecurityID', str)


SYMBOLS = {
    'ham': '4a24ab25-766d-4d6c-99e2-337da6d0ba45',
    'spam': 'e8248888-b413-4def-b11a-763b10faf9c0',
}  # type: Dict[Ticker, SecurityID]

INDICES = {
    'eggs',
    'mayo',
}  # type: Set[Ticker]

TICKERS = INDICES | SYMBOLS.keys() # type: Set[Ticker]

Results in:

s.py:7: error: List item 0 has incompatible type "Tuple[str, str]"
s.py:7: error: List item 1 has incompatible type "Tuple[str, str]"
s.py:12: error: Argument 1 to <set> has incompatible type "str"; expected "Ticker"
s.py:12: error: Argument 2 to <set> has incompatible type "str"; expected "Ticker"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions