Skip to content

[python-types] client.py: 9 router proxy methods return List[Any] and 3 watch methods have untyped callback #563

@realfishsam

Description

@realfishsam

File

sdks/python/pmxt/client.py

Note: This is an addendum to #227, which covers params: Optional[dict] and other issues in the same file. These findings were not included there.

Excessive Any — Router Proxy Methods Return List[Any] (CRITICAL)

The Exchange base class exposes 9 router-related methods that return List[Any]. The Router subclass properly overrides these with concrete types, but the base class is the declared type for every exchange instance. Users who call these methods on Polymarket, Kalshi, etc. (which do not override them) get List[Any] — no IDE completion on results.

Line Method Current return Should be
1135 fetch_market_matches List[Any] List[MatchResult]
1158 fetch_matches List[Any] List[MatchResult]
1180 fetch_event_matches List[Any] List[EventMatchResult]
1203 compare_market_prices List[Any] List[PriceComparison]
1225 fetch_related_markets List[Any] List[MatchResult]
1247 fetch_matched_markets List[Any] List[MatchResult]
1270 fetch_matched_prices List[Any] List[PriceComparison]
1293 fetch_hedges List[Any] List[PriceComparison]
1315 fetch_arbitrage List[Any] List[ArbitrageOpportunity]

All model classes (MatchResult, EventMatchResult, PriceComparison, ArbitrageOpportunity) are already imported from .models at the top of client.py.

Untyped callback Parameter — Watch Methods (HIGH)

Three watch methods accept callback: Optional[Any]. The callback parameter is not documented as to what signature it should have, making it impossible for users to know what function to pass, and for type checkers to validate call sites.

Line Method Parameter issue
2143 watch_prices(self, market_address: str, callback: Optional[Any] = None) -> Any callback untyped; return type Any
2179 watch_user_positions(self, callback: Optional[Any] = None) -> List[Position] callback untyped
2216 watch_user_transactions(self, callback: Optional[Any] = None) -> Any callback untyped; return type Any

Impact

  • Every caller of the 9 router proxy methods on any non-Router exchange gets Any back — zero IDE autocompletion on results.
  • watch_prices and watch_user_transactions return Any, leaving the full shape of streaming payloads invisible to type checkers.
  • callback being Optional[Any] means IDEs cannot validate whether a user-supplied callback has the right signature.

Suggested Fix

Router proxy methods

from .models import MatchResult, EventMatchResult, PriceComparison, ArbitrageOpportunity  # already imported

def fetch_market_matches(self, params: Optional[Dict[str, Any]] = None, **kwargs) -> List[MatchResult]: ...
def fetch_event_matches(self, params: Optional[Dict[str, Any]] = None, **kwargs) -> List[EventMatchResult]: ...
def compare_market_prices(self, params: Dict[str, Any], **kwargs) -> List[PriceComparison]: ...
def fetch_hedges(self, params: Dict[str, Any], **kwargs) -> List[PriceComparison]: ...
def fetch_arbitrage(self, params: Optional[Dict[str, Any]] = None, **kwargs) -> List[ArbitrageOpportunity]: ...
# etc.

Watch methods

from typing import Callable

def watch_prices(
    self,
    market_address: str,
    callback: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> Dict[str, Any]: ...

def watch_user_transactions(
    self,
    callback: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> Dict[str, Any]: ...

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