Skip to content

TP0200

Error: type mismatch

  • expected <T>, found <S> (annotations, arguments, return values, assignments)
  • operator '<op>' cannot be applied to <S> and <T>
  • operator '<op>' cannot be applied to <S>
  • cannot compare <S> and <T>
  • '<f>' does not return a value
  • '<f>' has no return type, so 'return' cannot have a value
  • missing return value; '<f>' returns <T>
  • '<x>' is not a function
  • cannot call <T> (a callee that isn’t a name)
  • '<f>' is generic, so it cannot be used as a value
  • built-in '<f>' cannot be used as a value, with help wrap it in a lambda (M11)
  • '<f>' has '*args' or '**kwargs', so it cannot be used as a value, with help wrap it in a lambda
  • cannot unpack <T> into arguments (M30)
  • '<f>' yields, so it must return 'Iterator[T]'
  • a generator can't return a value
  • cannot index <T>
  • cannot slice <T>
  • 'len' takes a list, dict or str, found <T>, each with help convert it with 'list(…)' first for an iterator (M31)
  • expected <T>, found lambda
  • cannot sort <T>, with help pass a key, e.g. 'key=lambda x: ...'
  • cannot sort by <K> (M11)
  • tuple index must be an integer literal
  • index <i> out of range for <T> (a tuple)
  • cannot unpack <T>
  • cannot slice <T> (M12)
  • integer literal is out of range
  • 'range' can only be used in a for loop
  • cannot iterate over <T>
  • '<T>' is inferred as both <A> and <B>
  • '<T>' must be <A> or <B>, found <C> (type-argument inference and constraints; A, B or C for longer tuples)
  • '<m>' is a module, not a value
  • 'as' converts py values; found <T>
  • cannot convert to <T>
  • cannot pass <T> to Python (§10)
  • cannot match on <T>
  • '<E>' is a type, not a value
  • '<v>' is not a function (a variant without a payload)
  • 'is some' needs an optional, found <T>
  • 'is None' needs an optional, found <T>
  • 'is not None' needs an optional, found <T>
  • '??' needs an optional on the left, found <T>
  • '<m>' is a method; call it
  • '<f>' is a field, not a method
  • cannot index <T>
  • dict keys must be int, str, bool, tuples of those, or plain class instances, found <T> (for a dataclass, with help a dataclass compares by value, so it cannot be a key; since M28 a class that isn’t hashable gets dict keys must be hashable, found <C> instead, §4.8)
  • isinstance needs a class, found <T>
  • '<C>' is not a class
  • '<C>' is generic
  • <T> can never be a <C> (isinstance, as and class patterns on unrelated classes)
  • '<C>' is a class; write '<C>()' (a class pattern without parentheses) (M15)
  • no overload of '<T>.<m>' takes (<A1>, <A2>)
  • '<T>' is a static class (constructing it, or using it as a type)
  • '<T>' cannot be constructed (an interface, abstract class or enum)
  • <v> is out of range for <N> (a literal argument, <N> the .NET type’s name, such as Int32)
  • '<T>.<m>' returned null (TypeError, at run time)
  • '<C>' is not an exception class (a .NET class not deriving from System.Exception)
  • cannot bind both Taipan and .NET exceptions, with help write separate clauses (M21)
  • '<n>' is a .NET namespace, not a value
  • a .NET exception can't have a cause, with help pass it to the constructor as the inner exception (for the cause)
  • '<E>' is an event; use '+=' or '-='
  • <S> can never be a <T> and '<T>' is generic for .NET types (isinstance, as and class patterns) (M43)
  • '<T>' does not satisfy '<P>': it has no field '<f>'
  • '<T>' does not satisfy '<P>': '<f>' must be '<f>: <F>'
  • '<T>' does not derive from '<C>'
  • <P> can never be a <C>
  • '<f>' cannot be used as a value, with help wrap it in a lambda
  • 'is' compares identity, which <T> doesn't have, with help use '=='
  • isinstance on py takes int, float, str, bool, list, dict, tuple or a Python class, found <T> (M40)
  • 'from' needs an exception or None, found <T> (with help write '<C>(…)' for a class name) (M41)
  • 'yield' needs a value: '<f>' yields <Y>
  • a generator declared '<T>' can't return a value, with help declare it 'Generator[Y, S, R]'
  • '<f>' can end without returning a <R>
  • 'yield from' over <T> gives no value
  • '<f>' is an async generator, so it must return 'AsyncIterator[T]'
  • an async generator can't return a value
  • cannot iterate over <T> with 'async for' (help use 'for' for a plain iterable)
  • <T> is not an async context manager (help use 'with' for a plain context manager, define '__aenter__' and '__aexit__' otherwise), and with with, help use 'async with'
  • object has no attribute '<a>', with help convert it with 'as' (M42)
  • expected Self, found <C>
  • a class attribute can't use '<T>'
  • '<m>' is generic, so it cannot be used as a value for a generic class’s static or class method without type arguments (M39)
  • <T> can't be None
  • <T> cannot match a mapping pattern
  • mapping keys must be int, str or bool, found <K>
  • alternatives bind different names: '<x>' is not bound in every one
  • '<x>' is <A> in one alternative and <B> in another (M38)
  • every arm of this 'match' raises, with help use a 'match' statement (M19)
  • this arm gives no value, with help end it with an expression
  • <T> cannot match a tuple pattern
  • <T> cannot match a list pattern
  • '*<x>' would hold <A> and <B> (a starred name in a tuple) (M29)
  • set elements must be hashable, found <T>
  • sum() takes numbers, found <T>, with help use ''.join(…) for str
  • 'any' takes bools, found <T> (and 'all'), with help test each value, as in any(x > 0 for x in xs)
  • 'min' needs values that can be ordered, found <T> (and 'max'), with help pass a key, e.g. 'key=lambda x: ...'
  • an int can't be raised to a negative power, with help use a float base, as in 2.0 ** -1 (M35)
  • <T> is not a context manager, with help define '__enter__' and '__exit__'
  • invalid mode '<m>', with help naming a deferred mode
  • 'open' needs a literal mode (and encoding, newline)
  • unknown encoding '<e>'
  • newline must be None or ''
  • 'type[…]' needs a class, found <T> (M37)
  • format spec '<spec>' isn't valid for <T>, with help naming the part that isn’t
  • format specs apply to int, float and str, found <T> (M26)
  • '<A>' is a type alias, not a value, with help use '<N>' when it names a class or enum (M18)
  • cannot raise <T> (with help write '<C>(…)' for a class name)
  • '<C>' is not an exception class
  • 'PythonError' cannot be constructed (and 'DotNetError', M21) (M16)
  • '<T>' does not satisfy '<P>': it has no method '<m>'
  • '<T>' does not satisfy '<P>': '<m>' must be 'def <m>(self, …) -> <R>' (the protocol’s signature with Self replaced; -> <R> left out when it returns nothing), at a call’s callee or a declared protocol, with (declared by '<B>') after '<P>' for an inherited declaration
  • '...' can only be the body of a protocol method
  • '<m>' cannot be called directly, with help use '<' (M17)
  • 'super()' can only be used as 'super().<method>(…)'
  • 'super()' can only be used in a method
  • '<C>' has no base class
  • '__init__' cannot be called directly
  • '__init__' cannot have a return type (M15)
  • '<m>' cannot be called directly, with help use '<form>' (a special method, as M17’s __lt__)
  • dict keys must be hashable, found <C>, with help as §4.8 says
  • cannot hash <T>
  • '+' on <A> and <B> is ambiguous: '<C>.__add__' would run when it fits
  • '<p>' is a property; read it from an instance
  • '<m>' needs an instance of '<C>'
  • 'cls' can only be called, or used to reach static and class methods and class attributes
  • 'ClassVar' can only annotate a class attribute
  • '<B>.<m>' is abstract (M28)

From the golden case tests/cases/m26/tp0200_everyday.tpn:

tp0200_everyday.tpn
# isinstance and zip mistakes (SPEC §6).
class A:
pass
class B:
pass
let a = A()
print(isinstance(a, (A, B)))
print(zip([1, 2]))

The compiler reports:

tp0200_everyday.tpn:9:25: error TP0200: A can never be a B
tp0200_everyday.tpn:10:7: error TP0209: 'zip' takes 2 or more arguments, found 1

The specification lists every code.