Skip to content

TP0302

Warning: warning: a library’s or extension module’s definition can’t be exported (M22, M25)

  • '<f>' is not exported: <reason>, where <reason> is its type parameter '<T>' has a bound
  • '<T>?' has no .NET generic form
  • it uses '<g>', which isn't a .NET generic
  • it uses '<C>', which isn't exported
  • it has its module's name (M22)
  • '<T>' can't be passed to Python
  • it's generic (M25)
  • it's used as the protocol '<P>' (M40)
  • '<T>' can't be passed to C
  • it's async
  • it has '*args' or '**kwargs'
  • it has keyword-only parameters (a native library) (M45), with help rename it '_<f>' to keep it private

From the golden case tests/cases/m40/tp0302_protocol_library.tpn:

tp0302_protocol_library.tpn
# In a library, a generic class used as a protocol type is compiled per instantiation, so it is not exported (SPEC §14.2).
class Getter[T](Protocol):
def get(self) -> T: ...
class Bag[T]:
value: T
def __init__(self, value: T):
self.value = value
def get(self) -> T:
return self.value
def read(g: Getter[int]) -> int:
return g.get()
def demo() -> int:
return read(Bag(5))

The compiler reports:

tp0302_protocol_library.tpn:5:7: warning TP0302: 'Bag' is not exported: it's used as the protocol 'Getter[int]'
help: rename it '_Bag' to keep it private

The specification lists every code.