Skip to content

[python-types] models.py: bare list[T] syntax in SubscribedAddressSnapshot breaks Python 3.8 #562

@realfishsam

Description

@realfishsam

File

sdks/python/pmxt/models.py

Missing Optional + Bare Built-in Generics (Python 3.9+ syntax)

Lines 483–489 in the SubscribedAddressSnapshot dataclass use the list[T] built-in generic form, which requires Python 3.9+:

Line Current Required for Python 3.8
483 trades: Optional[list[Trade]] = None Optional[List[Trade]]
485 positions: Optional[list[Position]] = None Optional[List[Position]]
487 balances: Optional[list[Balance]] = None Optional[List[Balance]]

On Python 3.8, the dataclass decorator evaluates field annotations at class-definition time. list[Trade] raises:

TypeError: 'type' object is not subscriptable

immediately on import pmxt.

Inconsistency

Every other collection type in models.py correctly uses List[T] from typing (e.g., outcomes: List[MarketOutcome], tags: Optional[List[str]]). These three fields are the only outliers — likely written on a Python 3.9+ machine and not caught because disallow_untyped_defs = false and tests presumably ran on Python 3.9+.

Impact

  • HIGH: SubscribedAddressSnapshot is the public return type of watch_address(). Any user on Python 3.8 calling watch_address() will receive a crash at import time before the call is even reached.
  • This also affects type checkers: list[Trade] is not List[Trade] in older mypy versions that target Python 3.8 semantics.

Suggested Fix

from typing import List, Optional  # already imported at top of file

@dataclass
class SubscribedAddressSnapshot:
    address: str
    timestamp: int
    trades: Optional[List[Trade]] = None
    positions: Optional[List[Position]] = None
    balances: Optional[List[Balance]] = None

Found by automated Python type hints audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions