Skip to content
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

[Typing] Using Sequence instead of list #3661

Merged
merged 7 commits into from
Jul 25, 2024
Merged

Conversation

zrr1999
Copy link
Contributor

@zrr1999 zrr1999 commented Jul 17, 2024

Description

Fixes #3660

Test Code

import flet as ft

controls = [
    ft.Text("Hello, World!"),
    ft.Text("Hello, World!"),
]

a = ft.Row(controls)
a = ft.Column(controls)
a = ft.Stack(controls)
a = ft.View(controls=controls)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots (if applicable):

Additional details

Summary by Sourcery

This pull request updates the type hints for 'controls' parameters from List[Control] to Sequence[Control] in various components to enhance flexibility in input types.

  • Enhancements:
    • Replaced type hints for 'controls' parameters from List[Control] to Sequence[Control] across multiple files to allow for more flexible input types.

Copy link
Contributor

sourcery-ai bot commented Jul 17, 2024

Reviewer's Guide by Sourcery

This pull request refactors the type annotations in various files to use Sequence instead of List for the controls parameter. This change enhances the flexibility of the code by allowing any sequence type (e.g., lists, tuples) to be passed, rather than restricting it to lists. Additionally, the code ensures that the controls parameter is converted to a list if it is not None.

File-Level Changes

Files Changes
sdk/python/packages/flet-core/src/flet_core/column.py
sdk/python/packages/flet-core/src/flet_core/cupertino_picker.py
sdk/python/packages/flet-core/src/flet_core/cupertino_segmented_button.py
sdk/python/packages/flet-core/src/flet_core/cupertino_sliding_segmented_button.py
sdk/python/packages/flet-core/src/flet_core/expansion_tile.py
sdk/python/packages/flet-core/src/flet_core/grid_view.py
sdk/python/packages/flet-core/src/flet_core/list_view.py
sdk/python/packages/flet-core/src/flet_core/menu_bar.py
sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py
sdk/python/packages/flet-core/src/flet_core/responsive_row.py
sdk/python/packages/flet-core/src/flet_core/row.py
sdk/python/packages/flet-core/src/flet_core/search_bar.py
sdk/python/packages/flet-core/src/flet_core/stack.py
sdk/python/packages/flet-core/src/flet_core/submenu_button.py
sdk/python/packages/flet-core/src/flet_core/view.py
Changed type annotations for controls from List[Control] to Sequence[Control] and converted controls to a list if it is not None.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @zrr1999 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 6 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@ndonkoHenri
Copy link
Contributor

Thanks for your contribution.
Please provide some code for review as suggested by the PR-Template.

@zrr1999 zrr1999 requested a review from ndonkoHenri July 19, 2024 05:16
Copy link
Contributor

@ndonkoHenri ndonkoHenri left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!
I pushed a review commit. Please modify the other files following this example.

  • we cast to a list in the setter (not in the init)
  • self.__controls = list(value) if value is not None else [] : when the setter looks like this (or similar), the getter should have a return type of list

@zrr1999
Copy link
Contributor Author

zrr1999 commented Jul 20, 2024

Thanks for your contribution! I pushed a review commit. Please modify the other files following this example.

  • we cast to a list in the setter (not in the init)
  • self.__controls = list(value) if value is not None else [] : when the setter looks like this (or similar), the getter should have a return type of list

Okay, I have finished making the changes.

@zrr1999 zrr1999 requested a review from ndonkoHenri July 20, 2024 14:06
@zrr1999 zrr1999 requested a review from ndonkoHenri July 21, 2024 05:01
Copy link
Contributor

@ndonkoHenri ndonkoHenri left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM.

@FeodorFitsner FeodorFitsner merged commit 27ffc23 into flet-dev:main Jul 25, 2024
2 checks passed
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.

Covariance in Python: Using Sequence[T] instead of list[T]
3 participants