Skip to content

Conversation

@purplesmoke05
Copy link
Member

📌 Description

This pull request focuses on type improvements, code cleanup, and simplification across several modules, with a particular emphasis on more precise type annotations, more idiomatic environment variable handling in configuration, and some minor bug fixes. The changes aim to make the codebase more robust, readable, and maintainable.

✅ Related Issues

🔄 Changes

Type Annotations and Model Improvements

  • Added or improved type annotations in various places for better static analysis and code clarity, including the use of Any, Type[Any], list[Type[BaseModel]], and more explicit types for cache and function arguments in app/contracts/abi.py and app/contracts/contract.py. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

  • Fixed and clarified usage of the Company type in API router and utility functions, ensuring consistent and correct typing for company objects. [1] [2] [3] [4] [5]

Configuration Simplification

  • Simplified environment variable parsing in app/config.py by replacing verbose conditional expressions with a more concise int(os.environ.get("VAR") or default) pattern, improving readability and reducing code duplication. [1] [2] [3] [4] [5] [6] [7] [8]

Imports and Linting

  • Added Pyright linting directives to suppress specific warnings in app/config.py and app/contracts/__init__.py for better static analysis compatibility. [1] [2]

Minor Bug Fixes and Cleanups

  • Fixed a bug where the company address was checked as an attribute instead of a dictionary key in the company info API.
  • Improved the merging of company data by using dictionary unpacking instead of calling .json().
  • Updated imports to use more specific modules and removed unused imports.

These changes collectively enhance code safety, maintainability, and clarity while fixing minor issues and ensuring more robust handling of data and configuration.

📌 Checklist

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

@github-actions
Copy link

github-actions bot commented Jan 15, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
app
   config.py107595%62–63, 67, 120, 159
   errors.py540100% 
   main.py1352085%108–109, 113, 118–120, 149–150, 193, 205–207, 218–220, 223, 227, 232, 236, 378
   validator.py100100% 
app/api/routers
   company_info.py96594%158–159, 288, 308, 326
app/contracts
   __init__.py30100% 
   abi.py80692%46–47, 90–91, 94, 102
   contract.py731382%93–94, 96–98, 100, 106, 109, 111, 113–114, 116, 143
app/database
   __init__.py461078%47, 54, 72, 108–110, 112, 128–129, 131
app/middleware
   __init__.py30100% 
   strip_trailing_slash.py21576%43–44, 58–60
app/model/blockchain
   token.py4932095%90, 139, 142, 245–246, 359–360, 382, 431–432, 439–440, 590–591, 688–689, 808–809, 887–888
app/model/db
   base.py18288%45, 48
   company.py23386%52, 79, 82
   executable_contract.py8187%31
   idx_agreement.py240100% 
   idx_block_data.py270100% 
   idx_consume_coupon.py120100% 
   idx_lock_unlock.py651084%95–98, 101, 160–163, 166
   idx_order.py200100% 
   idx_position.py520100% 
   idx_token.py91297%134, 191
   idx_token_list_register.py120100% 
   idx_transfer.py42197%97
   idx_transfer_approval.py38197%74
   idx_tx_data.py160100% 
   listing.py31390%52, 61, 70
   messaging.py170100% 
   node.py11190%42
   notification.py67395%50, 127, 136
   tokenholders.py230100% 
   user_info.py70100% 
app/utils
   asyncio_utils.py22195%37
   company_list.py85890%67, 117–119, 130, 146, 200–201
   docs_utils.py111991%81, 175–176, 182, 185, 210, 213, 222–223
   fastapi_utils.py17570%30–32, 39, 50
   o11y.py413514%27, 29, 43–45, 47–49, 52–53, 55–56, 62, 64–65, 68, 70–71, 74, 76–77, 80, 82–83, 86, 88–89, 94, 97–98, 100–102, 104–105
   web3_utils.py1536160%53–55, 59–60, 64–65, 69–70, 75–78, 81–82, 84, 92, 107–108, 129–130, 133–135, 138–140, 142–143, 145, 152–162, 166, 169–173, 175–176, 178, 182, 199–200, 224, 228, 231–235, 244
batch
   indexer_Block_Tx_Data.py1141884%184, 198–199, 201–209, 211–212, 216–219
   indexer_Consume_Coupon.py1451887%73–74, 79–81, 129, 181, 233–234, 243–246, 249, 253–256
   indexer_DEX.py2663487%90–91, 96–98, 167, 224–225, 241, 246–247, 263, 272, 298–299, 328–329, 352–353, 408, 411–412, 415, 534–535, 544–547, 550, 554–557
   indexer_Position_Bond.py91712086%100–103, 242, 266, 466–467, 485–486, 552–553, 571–572, 639–640, 658–659, 727–728, 746–747, 837–838, 857–858, 895–896, 933–934, 971–972, 1009–1010, 1047–1048, 1060, 1076–1077, 1103–1104, 1111, 1130–1131, 1138, 1155–1156, 1182–1183, 1185–1186, 1189–1191, 1201, 1219–1220, 1278–1279, 1291, 1307–1308, 1315, 1332–1333, 1335–1336, 1339–1341, 1357–1358, 1365, 1418–1419, 1431, 1447–1448, 1455, 1472–1473, 1475–1476, 1479–1481, 1497–1498, 1505, 1522–1523, 1530, 1583–1584, 1696–1697, 1728–1729, 1782–1783, 1863–1864, 2015, 2020–2021, 2035–2036, 2053–2054, 2066–2067, 2076–2079, 2082, 2086–2089
   indexer_Position_Coupon.py4946986%87–90, 229, 251, 409–410, 422, 438–439, 465–466, 473, 492–493, 500, 517–518, 544–545, 547–548, 551–553, 563, 581–582, 640–641, 653, 667–668, 675, 692–693, 695–696, 699–701, 717–718, 725, 782–783, 882–883, 938–939, 1031, 1036–1037, 1051–1052, 1069–1070, 1082–1083, 1092–1095, 1098, 1102–1105
   indexer_Position_Membership.py4767684%87–90, 229, 251, 385, 401–402, 428–429, 436, 455–456, 463, 480–481, 507–508, 510–511, 514–516, 526, 544–545, 603–604, 616, 630–631, 638, 655–656, 658–659, 662–664, 680–681, 688, 745–746, 846–847, 860, 866, 902–903, 935, 995, 1000–1001, 1006, 1009–1010, 1012–1016, 1033–1034, 1046–1047, 1056–1059, 1062, 1066–1069
   indexer_Position_Share.py91711887%102–103, 242, 264, 464–465, 483–484, 550–551, 569–570, 637–638, 656–657, 725–726, 744–745, 835–836, 855–856, 893–894, 931–932, 969–970, 1007–1008, 1045–1046, 1058, 1074–1075, 1101–1102, 1109, 1128–1129, 1136, 1153–1154, 1180–1181, 1183–1184, 1187–1189, 1199, 1217–1218, 1276–1277, 1289, 1305–1306, 1313, 1330–1331, 1333–1334, 1337–1339, 1355–1356, 1363, 1416–1417, 1429, 1445–1446, 1453, 1470–1471, 1473–1474, 1477–1479, 1495–1496, 1503, 1520–1521, 1528, 1581–1582, 1694–1695, 1726–1727, 1780–1781, 1861–1862, 2013, 2018–2019, 2033–2034, 2051–2052, 2064–2065, 2074–2077, 2080, 2084–2087
   indexer_PublicInfo_PublicAccountList.py1002377%62–63, 114, 117, 159–162, 164–171, 173–175, 179–182
   indexer_Token_Detail.py971188%136, 151–154, 159, 161, 165–168
   indexer_Token_Detail_ShortTerm.py921188%147, 162–165, 172, 174, 178–181
   indexer_Token_Holders.py3443988%105, 417–418, 450–451, 469–470, 477–478, 507–508, 539–540, 573–574, 609–610, 647–648, 673–675, 685–695, 697–698, 702–705
   indexer_Token_List_Event.py1231984%73–74, 137, 156, 163–164, 191–193, 245, 248–251, 254, 258–261
   indexer_Transfer.py3285184%98, 192–194, 250–254, 274, 295, 371, 375, 402, 404, 470, 487–488, 539, 556–557, 610, 627–628, 646–647, 650–658, 661–672, 676–679
   indexer_TransferApproval.py4268580%102–105, 113–116, 158–162, 199, 223, 298–300, 302–309, 311–312, 315–318, 320–323, 334–337, 401, 449–450, 486–487, 500, 508–509, 522, 536–537, 550, 556–557, 577–578, 591, 599–600, 620–621, 634, 642–643, 664–665, 777, 783–784, 786, 800, 806–807, 809, 827–828, 837–840, 843, 847–850
   log.py170100% 
   processor_Block_Sync_Status.py1612485%66, 256, 258, 269, 271, 302–306, 308–314, 316–317, 320, 324–327
   processor_Notifications_Coupon_Exchange.py3113489%106, 126–127, 132, 143, 160, 162, 188, 229, 270, 314, 355, 396, 437, 481, 522, 566, 593, 605, 607–608, 610–611, 614–616, 618–619, 621–622, 626–629
   processor_Notifications_Membership_Exchange.py3113489%106, 126–127, 132, 143, 160, 162, 188, 229, 273, 317, 358, 399, 443, 487, 531, 575, 602, 614, 616–617, 619–620, 623–625, 627–628, 630–631, 635–638
   processor_Notifications_Token.py3963890%156, 192, 215, 217, 224, 245–248, 377, 423, 469, 680, 730, 757, 764–765, 768–769, 821–822, 933, 945, 947–948, 950–951, 954–956, 958–959, 961–962, 966–969
   processor_Send_Chat_Webhook.py491863%52, 65–74, 76–78, 82–85
batch/lib
   token.py27485%31–32, 35–36
   token_list.py17288%39, 41
tests/batch
   indexer_Position_Bond_test.py10630100% 
   indexer_Position_Coupon_test.py5100100% 
   indexer_Position_Membership_test.py4790100% 
   indexer_Position_Share_test.py10600100% 
   indexer_PublicInfo_PublicAccountList_test.py1570100% 
TOTAL46550158296% 

Tests Skipped Failures Errors Time
1538 0 💤 0 ❌ 0 🔥 11m 37s ⏱️

LOG.info("Syncing to={}".format(block_to))

await self.__sync_transfer(db_session, block_to)
await self.__sync_consume(db_session, block_to)
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, I found a bug in the existing logic: the processing related to __sync_consume is not being executed.

@purplesmoke05 purplesmoke05 marked this pull request as ready for review January 15, 2026 11:34
@YoshihitoAso YoshihitoAso requested a review from Copilot January 15, 2026 14:36
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 pull request focuses on improving type safety and code quality by adding comprehensive type annotations, simplifying configuration handling, and removing unused code. The changes target type errors detected by Pyright across batch processing modules, configuration files, and various utilities.

Changes:

  • Added comprehensive type annotations to batch indexers, processors, and utility modules including proper typing for Web3 event data, contracts, and blockchain interactions
  • Simplified environment variable parsing in app/config.py using more concise int(os.environ.get("VAR") or default) pattern, reducing code verbosity
  • Refactored company data handling from property-based Company class to TypedDict-based approach for better type safety and simpler data access
  • Removed unused utility code including app/utils/alchemy.py, unused FIELDS dictionaries in database models, and deprecated helper functions

Reviewed changes

Copilot reviewed 69 out of 70 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
uv.lock, pyproject.toml Added types-botocore dependency for boto3 type stubs
pyrightconfig.json Extended Pyright coverage to include app/ and batch/ directories
batch/* files Added type annotations for event data, contracts, function signatures, and return types
app/config.py Simplified environment variable parsing and added pyright directive
app/utils/company_list.py Refactored Company from class to TypedDict for better type safety
app/model/db/* Removed unused FIELDS dictionaries from all database models
app/contracts/*.py Added proper type annotations for contract interactions
app/main.py, app/errors.py Added return type annotations to exception handlers and error classes
app/utils/*.py Enhanced type annotations in utility modules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…` and add comment for error handling in `indexer_Transfer.py`
@YoshihitoAso YoshihitoAso merged commit 064d0ed into dev-26.3 Jan 16, 2026
11 checks passed
@YoshihitoAso YoshihitoAso deleted the feature/#1719 branch January 16, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants