fix: use str Enum instead of enumerate for OrderType and AssetType#308
fix: use str Enum instead of enumerate for OrderType and AssetType#308skyc1e wants to merge 1 commit intoPolymarket:mainfrom
Conversation
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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): |
There was a problem hiding this comment.
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)
|
This is a duplicate of #153 |


Summary
OrderTypeandAssetTypeinclob_types.pyinherit from the builtinenumeratefunction instead ofenum.Enum. This means they don't behave as proper enums.Uses
(str, Enum)rather than plainEnumto preserve backwards compatibility —OrderTypevalues are passed directly into JSON payloads viaorder_to_json(), andAssetTypevalues are stringified in query params via__str__(). Thestrmixin ensuresOrderType.GTC == "GTC"remains true.Closes #251
Note
Low Risk
Low risk: replaces incorrect
enumerateinheritance withstr, Enumfor 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
OrderTypeandAssetTypeinclob_types.pyto be real enums by switching inheritance from the builtinenumeratetoEnum, mixed withstrto 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.