Skip to content

Conversation

@purplesmoke05
Copy link
Member

📌 Description

This pull request refactors the app/api/routers/position*.py and app/api/routers/token*.py module to improve type safety, clarity, and maintainability. The main changes include updating function signatures and variable types to use more precise custom types, ensuring correct handling of boolean flags, and replacing usage of __dict__ with a dedicated to_dict() method for token model serialization. The changes also introduce explicit casting and type annotations for better static analysis and future-proofing.

✅ Related Issues

🔄 Changes

Type and Serialization Improvements

  • Updated function signatures and variable declarations to use custom types like PositionDataDict and PositionsResponseDict, ensuring more accurate type checking throughout the codebase. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
  • Replaced usage of __dict__ with the to_dict() method for token model serialization, leading to more controlled and predictable output structures. [1] [2] [3] [4] [5] [6] [7]

Boolean and Type Handling

  • Ensured boolean flags like enable_index and include_token_details are explicitly cast to bool, preventing potential bugs from incorrect type usage. [1] [2] [3] [4] [5]
  • Used typing.cast for explicit type conversions when fetching query results, improving type safety and future compatibility with stricter ORM typing. [1] [2] [3] [4]

Minor API and Logging Adjustments

  • Changed logging for ServiceUnavailable exceptions to use str(e) for better readability. [1] [2] [3]
  • Updated imports and type references to use the new TokenBase model type, aligning with current code standards. [1] [2]

These changes collectively improve code quality, maintainability, and reliability of the position API logic.

📌 Checklist

  • I have added tests where necessary.
  • I have updated the documentation where necessary.

@github-actions github-actions bot requested a review from YoshihitoAso January 23, 2026 00:30
@purplesmoke05 purplesmoke05 marked this pull request as ready for review January 23, 2026 00:49
@github-actions
Copy link

Coverage

Coverage Report •
FileStmtsMissCoverMissing
app/api/routers
   position.py4204090%447, 454, 501–502, 523–528, 586–587, 614–615, 644–649, 689–690, 717–718, 747–752, 989–990, 1017–1018, 1057–1062
   position_lock.py1610100% 
   token.py457798%492, 603, 734, 748, 752, 1108, 1383
   token_bond.py140695%326–331
   token_coupon.py140695%308–313
   token_lock.py650100% 
   token_membership.py140695%314–319
   token_share.py140695%324–329
app/model/blockchain
   token.py7422796%99, 155, 159, 162, 165, 168, 343–344, 517–518, 540, 590–591, 598–599, 630–631, 798–799, 938–939, 984–985, 1091–1092, 1206–1207
app/model/schema
   __init__.py220100% 
   position.py1690100% 
   token.py2180100% 
   token_bond.py910100% 
   token_coupon.py61198%33
   token_membership.py61198%33
   token_share.py750100% 
TOTAL46988158196% 

Tests Skipped Failures Errors Time
1538 0 💤 0 ❌ 0 🔥 12m 16s ⏱️

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.

[Pyright] Fix type errors in app/api/routers/position* [Pyright] Fix type errors in app/api/routers/token*

1 participant