Skip to content

TP0222

Error: top-level statement in an imported module, or in a library’s main file (M22) or an extension module (M25)

  • only the main file can have top-level statements
  • a library can't have top-level statements (M22)
  • a Python extension can't have top-level statements (M25)

From the golden case tests/cases/m45/tp0222_native_library.tpn:

tp0222_native_library.tpn
# A native library has no top level (SPEC §15.6).
print("hello")
def f() -> int:
return 1

The compiler reports:

tp0222_native_library.tpn:2:1: error TP0222: a native library can't have top-level statements

The specification lists every code.