Skip to content

TP0225

Error: invalid class definition

  • a class can have only one base class (protocols aside, M17)
  • '<T>' cannot be a base class
  • a dataclass can only derive from a dataclass (with help exceptions are plain classes; give it an '__init__' for an exception base, M16; since M41 only for a plain user exception class, SystemExit, PythonError or DotNetError)
  • a plain class can only derive from a plain class
  • generic classes cannot be derived from
  • generic classes cannot have a base class
  • '<C>' derives from itself
  • special method '<m>' is not supported
  • a dataclass cannot define '__init__'
  • field without a default follows field with a default
  • '<m>' must be 'def <m>(self, …) -> <R>' (M28, replacing M17’s '__lt__' must take one parameter of type '<C>' (or a base class) and return bool)
  • '<m>' must take 'self' first (or 'cls')
  • a static method takes neither 'self' nor 'cls'
  • a property takes no parameters other than 'self'
  • a property must have a return type
  • a setter must follow its property
  • a setter must take one parameter of type <T> and return nothing
  • class attribute '<a>' needs a value (generic classes cannot have <static methods|class methods|class attributes> until M39)
  • an abstract method's body must be '...'
  • '<C>' would not be hashable, but its base '<B>' is, with help define '__hash__' (M28)
  • '<C>' defines '__exit__' but not '__enter__' (or the reverse) (M37)
  • '<P>' is already declared (or already declared by '<B>')
  • a protocol can only declare methods
  • a protocol method's body must be '...'
  • protocol method parameters cannot have defaults
  • protocols cannot be generic
  • a protocol can only derive from 'Protocol' (M17)
  • a protocol field can't have a default
  • an exception class can't be generic (M40)
  • a frozen dataclass can't derive from one that isn't (or the reverse)
  • 'order=True' needs fields that can be ordered: '<f>' is <T>
  • 'order=True' generates '<m>'; remove it
  • '__post_init__' must be 'def __post_init__(self) -> None'
  • '__post_init__' is only for dataclasses
  • cannot derive from final class '<C>'
  • '@total_ordering' needs '__lt__', '__le__', '__gt__' or '__ge__' (M39)
  • cannot derive from '<B>': it's <sealed|static|a struct|an exception class|without a constructor Taipan can call> (with help derive from 'Exception' for an exception class)
  • '<C>' must define '<m>' to implement '<I>'
  • '<C>' must override '<B>.<m>'
  • '<m>' is defined by '<special>'
  • '<C>' derives from the .NET class '<B>', so it can't be derived from yet
  • generic classes cannot implement .NET interfaces yet (M43)

From the golden case tests/cases/m21/tp0225_dotneterror.tpn:

tp0225_dotneterror.tpn
class Mine(DotNetError):
pass

The compiler reports:

tp0225_dotneterror.tpn:1:12: error TP0225: 'DotNetError' cannot be a base class

The specification lists every code.