-
Notifications
You must be signed in to change notification settings - Fork 599
Replace more assertions with if-raise conditions #5721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine
There was a problem hiding this 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 replaces internal assertions with explicit runtime checks that raise well-defined exceptions and updates related docstrings accordingly.
- Swapped assert statements for conditional checks raising ValueError, RuntimeError, or FletUnsupportedPlatformException where appropriate.
- Updated docstrings to reflect new exception types and improved phrasing/links.
- Minor refactors and cleanup in example snippets and messages.
Reviewed Changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/utils/pip.py | Replace asserts with explicit version mismatch checks; still installs on exceptions. |
| sdk/python/packages/flet/src/flet/testing/flet_test_app.py | Convert asserts to raises; adjust error messages for clarity; change screenshot comparison behavior. |
| sdk/python/packages/flet/src/flet/pubsub/pubsub_hub.py | Replace assert with RuntimeError when event loop is missing. |
| sdk/python/packages/flet/src/flet/controls/services/shared_preferences.py | Replace assert with ValueError for None values. |
| sdk/python/packages/flet/src/flet/controls/material/menu_bar.py | Replace assert in before_update with ValueError; docstring updates. |
| sdk/python/packages/flet/src/flet/controls/material/expansion_panel.py | Replace asserts with raises; docstrings simplified/updated. |
| sdk/python/packages/flet/src/flet/controls/material/dropdownm2.py | Replace assert with ValueError; doc updated. |
| sdk/python/packages/flet/src/flet/controls/material/dropdown.py | Doc updates for exception types and text. |
| sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_colors.py | Replace assert with ValueError in with_opacity; doc updated. |
| sdk/python/packages/flet/src/flet/controls/control_event.py | Replace assert with RuntimeError when control has no page. |
| sdk/python/packages/flet/src/flet/controls/context.py | Docstring updated to reflect RuntimeError. |
| sdk/python/packages/flet/src/flet/controls/colors.py | Replace assert with ValueError in with_opacity; doc updated. |
| sdk/python/packages/flet/src/flet/controls/box.py | Replace asserts with ValueError in post_init validations. |
| sdk/python/packages/flet/src/flet/controls/border.py | Docstring update for ValueError. |
| sdk/python/packages/flet/src/flet/controls/base_page.py | Replace assert with RuntimeError when views are empty. |
| sdk/python/packages/flet/src/flet/controls/base_control.py | Replace asserts with RuntimeError for missing page before update/invoke/trigger. |
| sdk/python/packages/flet-webview/src/flet_webview/webview.py | Replace assert with RuntimeError for page presence. |
| sdk/python/packages/flet-web/src/flet_web/fastapi/flet_app.py | Replace assert with RuntimeError for missing upload path. |
| sdk/python/packages/flet-video/src/flet_video/video.py | Replace asserts with ValueError; tighten index checks and messages; doc updates. |
| sdk/python/packages/flet-video/src/flet_video/types.py | Doc link updates. |
| sdk/python/packages/flet-permission-handler/src/flet_permission_handler/types.py | Doc link updates. |
| sdk/python/packages/flet-map/src/flet_map/types.py | Replace asserts with ValueError; doc updates; link cleanups. |
| sdk/python/packages/flet-map/src/flet_map/tile_layer.py | Replace asserts with ValueError; per-field validation docs; link fixes. |
| sdk/python/packages/flet-map/src/flet_map/source_attribution.py | Replace assert with ValueError for visibility; doc updates. |
| sdk/python/packages/flet-map/src/flet_map/simple_attribution.py | Doc link update. |
| sdk/python/packages/flet-map/src/flet_map/polyline_layer.py | Replace asserts with ValueError in validation; doc updates. |
| sdk/python/packages/flet-map/src/flet_map/polygon_layer.py | Replace assert with ValueError; doc updates. |
| sdk/python/packages/flet-map/src/flet_map/marker_layer.py | Replace asserts with ValueError; doc updates. |
| sdk/python/packages/flet-map/src/flet_map/map.py | Replace asserts with ValueError; doc tweaks. |
| sdk/python/packages/flet-map/src/flet_map/circle_layer.py | Replace assert with ValueError; doc updates. |
| sdk/python/packages/flet-lottie/src/flet_lottie/lottie.py | Replace assert with ValueError for required src/src_base64; doc updates. |
| sdk/python/packages/flet-geolocator/src/flet_geolocator/geolocator.py | Replace asserts with FletUnsupportedPlatformException; doc updates. |
| sdk/python/packages/flet-desktop/src/flet_desktop/init.py | Replace assert with FileNotFoundError; minor import reordering. |
| sdk/python/packages/flet-datatable2/src/flet_datatable2/datacolumn2.py | Doc link update. |
| sdk/python/packages/flet-charts/src/flet_charts/pie_chart_section.py | Replace asserts with ValueError in validation; doc updates. |
| sdk/python/packages/flet-charts/src/flet_charts/line_chart_data_point.py | Doc link update. |
| sdk/python/packages/flet-charts/src/flet_charts/line_chart_data.py | Doc link update. |
| sdk/python/packages/flet-charts/src/flet_charts/chart_axis.py | Doc link updates. |
| sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py | Doc link updates and text tweaks. |
| sdk/python/packages/flet-audio/src/flet_audio/audio.py | Replace assert with ValueError; doc updates. |
| sdk/python/packages/flet-audio-recorder/src/flet_audio_recorder/audio_recorder.py | Replace assert with ValueError; doc updates. |
| sdk/python/packages/flet-ads/src/flet_ads/native_ad.py | Replace assert with ValueError; doc updates. |
| sdk/python/packages/flet-ads/src/flet_ads/interstitial_ad.py | Doc update to FletUnsupportedPlatformException. |
| sdk/python/packages/flet-ads/src/flet_ads/base_ad.py | Replace assert with FletUnsupportedPlatformException; doc updates. |
| sdk/python/packages/flet-ads/src/flet_ads/banner_ad.py | Doc update to FletUnsupportedPlatformException. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
sdk/python/packages/flet/src/flet/controls/material/expansion_panel.py
Outdated
Show resolved
Hide resolved
sdk/python/packages/flet/src/flet/controls/material/menu_bar.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Deploying flet-docs with
|
| Latest commit: |
0dc41d4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6dc412c6.flet-docs.pages.dev |
| Branch Preview URL: | https://replace-more-assertions.flet-docs.pages.dev |
sdk/python/packages/flet-charts/src/flet_charts/pie_chart_section.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary by Sourcery
Replace assertion-based validations with explicit exception raises and refine documentation
Enhancements:
assertstatements with explicitifchecks raisingValueError,RuntimeError,IndexError,FletUnsupportedPlatformException, orFileNotFoundErrorfor invalid inputs in map, UI controls, video, audio, and other classes(c)anchorsRuntimeErroron package version mismatches and useFileNotFoundErrorfor missing application bundles