Skip to content

fix: use str Enum instead of enumerate for OrderType and AssetType#308

Open
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/enum-inheritance
Open

fix: use str Enum instead of enumerate for OrderType and AssetType#308
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/enum-inheritance

Conversation

@skyc1e
Copy link
Copy Markdown

@skyc1e skyc1e commented Mar 24, 2026

Summary

OrderType and AssetType in clob_types.py inherit from the builtin enumerate function instead of enum.Enum. This means they don't behave as proper enums.

Uses (str, Enum) rather than plain Enum to preserve backwards compatibility — OrderType values are passed directly into JSON payloads via order_to_json(), and AssetType values are stringified in query params via __str__(). The str mixin ensures OrderType.GTC == "GTC" remains true.

Closes #251


Note

Low Risk
Low risk: replaces incorrect enumerate inheritance with str, Enum for two type definitions; behavioral impact should be limited to enum semantics/serialization but could affect any code relying on the previous non-enum behavior.

Overview
Fixes OrderType and AssetType in clob_types.py to be real enums by switching inheritance from the builtin enumerate to Enum, mixed with str to keep them JSON/query-param friendly.

This improves type safety and enum behavior (e.g., comparisons/validation) while preserving string compatibility for existing request-building paths that pass these values through.

Written by Cursor Bugbot for commit e439018. This will update automatically on new commits. Configure here.

OrderType and AssetType incorrectly inherit from the builtin
enumerate function instead of enum.Enum. This causes them to
not behave as proper enums.

Uses (str, Enum) to preserve backwards compatibility with existing
string comparisons and JSON serialization throughout the codebase.

Closes Polymarket#251
@skyc1e skyc1e requested a review from a team as a code owner March 24, 2026 00:55
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.



class AssetType(enumerate):
class AssetType(str, Enum):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssetType.__str__() returns enum name, not value

High Severity

Inheriting from (str, Enum) causes Enum.__str__ to take MRO priority over str.__str__, so AssetType.COLLATERAL.__str__() returns "AssetType.COLLATERAL" instead of "COLLATERAL" across all Python versions. This breaks add_balance_allowance_params_to_url in helpers.py, which calls params.asset_type.__str__() to build query parameters — the server will receive asset_type=AssetType.COLLATERAL instead of asset_type=COLLATERAL. The existing test at test_helpers.py:89 would also fail. A __str__ override returning self.value on both enum classes would fix this.

Additional Locations (1)
Fix in Cursor Fix in Web

@rian-dolphin
Copy link
Copy Markdown

This is a duplicate of #153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AssetType incorrectly derives from enumerate

2 participants