Skip to content

Conversation

@CorralPeltzer
Copy link

@CorralPeltzer CorralPeltzer commented Jun 11, 2025

Description

The recommended way to retrieve allowance emits a typing issue in pyright

    collateral = client.get_balance_allowance(
        params=BalanceAllowanceParams(asset_type=AssetType.COLLATERAL)
    )
Argument of type "Literal['COLLATERAL']" cannot be assigned to parameter "asset_type" of type "AssetType" in function "__init__"
  "Literal['COLLATERAL']" is not assignable to "AssetType"

This is due to incorrect usage of enumerate, which in python is unrelated to Enums, see https://docs.python.org/3/library/functions.html#enumerate

I have changed to the correct StrEnum class for AssetType and OrderType, see https://docs.python.org/3/library/enum.html

Testing instructions

Should be covered by existing tests

Types of changes

  • Bug fix/behavior correction

Status

  • Verify all tests run correctly in CI and pass.
  • Ready for review/merge.

Copilot AI review requested due to automatic review settings June 11, 2025 18:44

This comment was marked as outdated.

@CorralPeltzer CorralPeltzer requested a review from Copilot June 11, 2025 22:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a typing issue by correcting the usage of enums in the AssetType and OrderType classes. The changes involve replacing the incorrect usage of enumerate with StrEnum and updating related query parameter handling.

  • Replace incorrect enum usage with StrEnum for AssetType and OrderType.
  • Remove unnecessary string conversion when passing enum values to build_query_params.
  • Resolve Pyright typing errors in asset allowance queries.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
py_clob_client/http_helpers/helpers.py Updated asset_type conversion to pass StrEnum directly to query parameter builder
py_clob_client/clob_types.py Replaced incorrect usage of enumerate with StrEnum for OrderType and AssetType
Comments suppressed due to low confidence (3)

py_clob_client/http_helpers/helpers.py:147

  • Since AssetType is now defined as a StrEnum (inheriting from str), passing it directly is appropriate. Confirm that all consumers of this API expect the asset_type value to be a string.
url = build_query_params(url, "asset_type", params.asset_type)

py_clob_client/clob_types.py:13

  • Replacing 'enumerate' with 'StrEnum' corrects the enum type definition and resolves the Pyright typing issue. Ensure that all enum comparisons and assignments are updated to reflect the new enum behavior.
class OrderType(StrEnum):

py_clob_client/clob_types.py:178

  • Changing the definition from 'enumerate' to 'StrEnum' for AssetType fixes the type mismatch error. Make sure that any logic relying on AssetType's string representation is verified post-change.
class AssetType(StrEnum):

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.

1 participant