Commit 47c82ec
refactor(waterdata): /simplify pass 2 — encapsulate session sharing, drop duplicate json parse
Follow-up cleanup on the chunker module driven by another code review:
- _publish_session contextmanager wraps the _chunked_session
ContextVar set/reset token dance. ChunkedCall.resume becomes a single
`with requests.Session() as s, _publish_session(s):` line.
- Push the ContextVar lookup INTO `_session()` itself (resolution order:
caller-provided -> chunker's shared -> fresh temp). _paginate no
longer reaches across modules into `chunking._chunked_session`.
- Add `body` kwarg to `_get_resp_data` and `_next_req_url` so
`_walk_pages` can `resp.json()` once and reuse the body across both
helpers — eliminates a per-page redundant JSON parse on the OGC
pagination path (~halves JSON-decode CPU per page).
- TypeVar `_Cursor` on `_paginate` so the two callbacks
(parse_response, follow_up) are linked through the type system
rather than `Any → Any`. Type checkers can now catch a cursor-type
mismatch at a single call site.
- get_stats_data's follow_up no longer mutates the caller's args dict
— uses `params={**args, "next_token": cursor}` instead of
`args["next_token"] = cursor`.
- Switch _walk_pages's lambdas to named inner functions to match
get_stats_data's style.
- Hoist the `RateLimited` import in
test_chunked_session_isolated_per_resume to module level (was inside
the fetch closure).
- Drop one redundant multi-line "PreparedRequest.method is already
upper-cased" comment in _walk_pages (the inline form in
get_stats_data is enough context for the codebase).
80 chunker + utils unit tests pass; ruff clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 4e44906 commit 47c82ec
3 files changed
Lines changed: 91 additions & 54 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
111 | 127 | | |
112 | 128 | | |
113 | 129 | | |
| |||
1022 | 1038 | | |
1023 | 1039 | | |
1024 | 1040 | | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1041 | 1053 | | |
1042 | 1054 | | |
1043 | 1055 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
681 | | - | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
682 | 684 | | |
683 | 685 | | |
684 | 686 | | |
| |||
687 | 689 | | |
688 | 690 | | |
689 | 691 | | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
690 | 696 | | |
691 | 697 | | |
692 | 698 | | |
| |||
702 | 708 | | |
703 | 709 | | |
704 | 710 | | |
705 | | - | |
| 711 | + | |
| 712 | + | |
706 | 713 | | |
707 | 714 | | |
708 | 715 | | |
| |||
719 | 726 | | |
720 | 727 | | |
721 | 728 | | |
722 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
723 | 735 | | |
724 | 736 | | |
725 | 737 | | |
| |||
731 | 743 | | |
732 | 744 | | |
733 | 745 | | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
734 | 750 | | |
735 | 751 | | |
736 | 752 | | |
| |||
739 | 755 | | |
740 | 756 | | |
741 | 757 | | |
742 | | - | |
743 | | - | |
| 758 | + | |
| 759 | + | |
744 | 760 | | |
745 | 761 | | |
746 | 762 | | |
| |||
771 | 787 | | |
772 | 788 | | |
773 | 789 | | |
774 | | - | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
775 | 793 | | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
780 | 801 | | |
781 | 802 | | |
782 | 803 | | |
783 | 804 | | |
784 | | - | |
785 | | - | |
| 805 | + | |
| 806 | + | |
786 | 807 | | |
787 | 808 | | |
788 | 809 | | |
789 | 810 | | |
790 | | - | |
791 | | - | |
| 811 | + | |
792 | 812 | | |
793 | 813 | | |
794 | 814 | | |
795 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
796 | 820 | | |
797 | 821 | | |
798 | 822 | | |
| |||
833 | 857 | | |
834 | 858 | | |
835 | 859 | | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
836 | 863 | | |
837 | 864 | | |
838 | 865 | | |
839 | 866 | | |
840 | | - | |
841 | | - | |
| 867 | + | |
| 868 | + | |
842 | 869 | | |
843 | 870 | | |
844 | 871 | | |
| |||
898 | 925 | | |
899 | 926 | | |
900 | 927 | | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | 928 | | |
908 | 929 | | |
909 | 930 | | |
| |||
973 | 994 | | |
974 | 995 | | |
975 | 996 | | |
976 | | - | |
977 | | - | |
978 | | - | |
| 997 | + | |
979 | 998 | | |
980 | 999 | | |
981 | 1000 | | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
982 | 1011 | | |
983 | 1012 | | |
984 | 1013 | | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
| 1014 | + | |
| 1015 | + | |
992 | 1016 | | |
993 | 1017 | | |
994 | 1018 | | |
| |||
1409 | 1433 | | |
1410 | 1434 | | |
1411 | 1435 | | |
1412 | | - | |
1413 | | - | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1414 | 1441 | | |
1415 | 1442 | | |
1416 | 1443 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
373 | | - | |
374 | 372 | | |
375 | 373 | | |
376 | 374 | | |
| |||
0 commit comments