|
131 | 131 | { |
132 | 132 | "data": { |
133 | 133 | "text/plain": [ |
134 | | - "datetime.datetime(2024, 12, 4, 14, 0)" |
| 134 | + "datetime.datetime(2024, 12, 10, 14, 0)" |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | "execution_count": null, |
|
2423 | 2423 | "name": "stdout", |
2424 | 2424 | "output_type": "stream", |
2425 | 2425 | "text": [ |
2426 | | - "Set to 2024-12-04 09:20:09.428221\n" |
| 2426 | + "Set to 2024-12-10 09:54:42.331681\n" |
2427 | 2427 | ] |
2428 | 2428 | }, |
2429 | 2429 | { |
2430 | 2430 | "data": { |
2431 | 2431 | "text/plain": [ |
2432 | | - "'Session time: 2024-12-04 09:20:09.428221'" |
| 2432 | + "'Session time: 2024-12-10 09:54:42.331681'" |
2433 | 2433 | ] |
2434 | 2434 | }, |
2435 | 2435 | "execution_count": null, |
|
2620 | 2620 | " def __init__(self): super().__setattr__('_funcs', {})\n", |
2621 | 2621 | " def __setattr__(self, name, value): self._funcs[name] = value\n", |
2622 | 2622 | " def __getattr__(self, name): \n", |
2623 | | - " if name in all_meths: raise KeyError(\"Route functions with HTTP Names are not accessible here\")\n", |
2624 | | - " return self._funcs[name]\n", |
| 2623 | + " if name in all_meths: raise AttributeError(\"Route functions with HTTP Names are not accessible here\")\n", |
| 2624 | + " try: return self._funcs[name]\n", |
| 2625 | + " except KeyError: raise AttributeError(f\"No route named {name} found in route functions\")\n", |
2625 | 2626 | " def __dir__(self): return list(self._funcs.keys())" |
2626 | 2627 | ] |
2627 | 2628 | }, |
|
2656 | 2657 | " self.routes.append((func, p, methods, name, include_in_schema, body_wrap))\n", |
2657 | 2658 | " return wrapped\n", |
2658 | 2659 | " return f(path) if callable(path) else f\n", |
| 2660 | + " \n", |
| 2661 | + " def __getattr__(self, name):\n", |
| 2662 | + " try: return getattr(self.rt_funcs, name)\n", |
| 2663 | + " except AttributeError: return super().__getattr__(self, name)\n", |
2659 | 2664 | "\n", |
2660 | 2665 | " def to_app(self, app):\n", |
2661 | 2666 | " \"Add routes to `app`\"\n", |
|
2720 | 2725 | "metadata": {}, |
2721 | 2726 | "outputs": [], |
2722 | 2727 | "source": [ |
2723 | | - "assert str(ar.rt_funcs.index) == '/'\n", |
2724 | 2728 | "assert str(yoyo) == '/yoyo'\n", |
| 2729 | + "# ensure route functions are properly discoverable on `APIRouter` and `APIRouter.rt_funcs`\n", |
| 2730 | + "assert ar.prefix == ''\n", |
| 2731 | + "assert str(ar.rt_funcs.index) == '/'\n", |
| 2732 | + "assert str(ar.index) == '/'\n", |
| 2733 | + "with ExceptionExpected(): ar.blah()\n", |
| 2734 | + "with ExceptionExpected(): ar.rt_funcs.blah()\n", |
| 2735 | + "# ensure any route functions named using an HTTPMethod are not discoverable via `rt_funcs`\n", |
2725 | 2736 | "assert \"get\" not in ar.rt_funcs._funcs.keys()" |
2726 | 2737 | ] |
2727 | 2738 | }, |
|
2806 | 2817 | "metadata": {}, |
2807 | 2818 | "outputs": [], |
2808 | 2819 | "source": [ |
2809 | | - "assert str(ar2.rt_funcs.index) == '/products/'\n", |
2810 | 2820 | "assert str(yoyo) == '/products/yoyo'\n", |
| 2821 | + "assert ar2.prefix == '/products'\n", |
| 2822 | + "assert str(ar2.rt_funcs.index) == '/products/'\n", |
| 2823 | + "assert str(ar2.index) == '/products/'\n", |
| 2824 | + "assert str(ar.index) == '/'\n", |
| 2825 | + "with ExceptionExpected(): ar2.blah()\n", |
| 2826 | + "with ExceptionExpected(): ar2.rt_funcs.blah()\n", |
2811 | 2827 | "assert \"get\" not in ar2.rt_funcs._funcs.keys()" |
2812 | 2828 | ] |
2813 | 2829 | }, |
|
2933 | 2949 | { |
2934 | 2950 | "data": { |
2935 | 2951 | "text/plain": [ |
2936 | | - "'Cookie was set at time 09:20:09.542569'" |
| 2952 | + "'Cookie was set at time 09:54:43.255286'" |
2937 | 2953 | ] |
2938 | 2954 | }, |
2939 | 2955 | "execution_count": null, |
|
0 commit comments