Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP: Custom frozen dataclasses#586

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
tony wants to merge9 commits intomaster
base:master
Choose a base branch
Loading
fromfrozen-dataclasses-custom

Conversation

@tony
Copy link
Member

@tonytony commentedFeb 28, 2025
edited
Loading

Resolves#588

Summary by Sourcery

Tests:

  • Adds comprehensive tests for thefrozen_dataclass decorator, covering initialization, immutability, inheritance, edge cases, nested mutability, bidirectional references, and mutation methods.

@sourcery-ai
Copy link

sourcery-aibot commentedFeb 28, 2025
edited
Loading

Reviewer's Guide by Sourcery

This pull request introduces afrozen_dataclass decorator that allows creating immutable dataclasses that inherit from mutable ones. It includes comprehensive tests and configurations for mypy and ruff.

Class diagram for frozen_dataclass decorator

classDiagram    class frozen_dataclass {        +__init__(cls: type[_T]) type[_T]    }    class dataclasses.dataclass {        +__init__(frozen: bool)    }    class cls {        +__setattr__(name: str, value: t.Any) None        +__delattr__(name: str) None        -_frozen: bool    }    frozen_dataclass --|> dataclasses.dataclass: Uses    frozen_dataclass --|> cls: Decorates
Loading

File-Level Changes

ChangeDetailsFiles
Introduces afrozen_dataclass decorator to create immutable dataclasses inheriting from mutable ones.
  • Adds afrozen_dataclass decorator.
  • Applies@dataclasses.dataclass(frozen=False) to preserve dataclass generation.
  • Overrides__setattr__ and__delattr__ to prevent changes after initialization.
  • Adds a_frozen attribute to control immutability.
  • Includes documentation and examples for the decorator.
src/libtmux/_internal/frozen_dataclass.py
Adds tests for thefrozen_dataclass decorator, covering initialization, immutability, inheritance, and edge cases.
  • Creates base and snapshot dataclasses for testing.
  • Tests immutability by attempting to modify fields and verifyingAttributeError exceptions.
  • Tests inheritance from mutable base classes.
  • Tests internal attribute modification.
  • Tests nested mutability.
  • Tests bidirectional references.
  • Adds parametrized tests for dimensions and frozen flag behavior.
  • Adds tests for mutation methods and inheritance behavior.
tests/_internal/test_frozen_dataclass.py
Configures mypy to ignoremethod-assign errors for thefrozen_dataclass module.
  • Adds a mypy override to disablemethod-assign errors for thelibtmux._internal.frozen_dataclass module.
pyproject.toml
Configures ruff to ignoreB010 (set-attr-with-constant) errors for thefrozen_dataclass module.
  • Adds a ruff ignore rule to disableB010 errors for thesrc/libtmux/_internal/frozen_dataclass.py module.
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment@sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with@sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write@sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write@sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment@sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment@sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment@sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment@sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment@sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access yourdashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link

codecovbot commentedFeb 28, 2025
edited
Loading

Codecov Report

Attention: Patch coverage is84.23645% with32 lines in your changes missing coverage. Please review.

Project coverage is 80.25%. Comparing base(5803841) to head(0975cfd).
Report is 55 commits behind head on master.

Files with missing linesPatch %Lines
src/libtmux/_internal/frozen_dataclass_sealable.py79.25%20 Missing and 8 partials⚠️
src/libtmux/_internal/frozen_dataclass.py92.85%1 Missing and 1 partial⚠️
.../_internal/frozen_dataclass_sealable/test_basic.py95.00%1 Missing and 1 partial⚠️
Additional details and impacted files
@@            Coverage Diff             @@##           master     #586      +/-   ##==========================================+ Coverage   79.83%   80.25%   +0.42%==========================================  Files          22       25       +3       Lines        1914     2117     +203       Branches      294      338      +44     ==========================================+ Hits         1528     1699     +171- Misses        266      288      +22- Partials      120      130      +10

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tonytonyforce-pushed thefrozen-dataclasses-custom branch 9 times, most recently fromd4dc6e7 toa490526CompareFebruary 28, 2025 13:17
@tony
Copy link
MemberAuthor

@sourcery-ai review

sourcery-ai[bot] reacted with eyes emoji

Copy link

@sourcery-aisourcery-aibot left a comment

Choose a reason for hiding this comment

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

Hey@tony - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a note about the performance implications of using__setattr__ and__delattr__.
  • It would be helpful to include a warning in the documentation about the potential for users to bypass the immutability by modifying the_frozen attribute.
Here's what I looked at during the review
  • 🟢General issues: all looks good
  • 🟢Security: all looks good
  • 🟡Testing: 1 issue found
  • 🟢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 and I'll use the feedback to improve your reviews.

sourcery-ai[bot] reacted with thumbs up emojisourcery-ai[bot] reacted with thumbs down emoji
width=80,
height=24,
expected_error=False,
),

Choose a reason for hiding this comment

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

issue (testing): Edge case: Unfreezing via _frozen attribute

Although tested, the ability to unfreeze by modifying_frozen is a security risk. Consider making_frozen a property with a private setter to prevent this or document this behavior clearly as a known limitation.

sourcery-ai[bot] reacted with thumbs up emojisourcery-ai[bot] reacted with thumbs down emoji
@tonytonyforce-pushed thefrozen-dataclasses-custom branch 4 times, most recently fromd2c13aa to70e415cCompareFebruary 28, 2025 18:57
@tonytony mentioned this pull requestFeb 28, 2025
@tonytonyforce-pushed thefrozen-dataclasses-custom branch 7 times, most recently from4353421 toe18198bCompareMarch 1, 2025 00:03
@tonytonyforce-pushed thefrozen-dataclasses-custom branch 4 times, most recently frome77bc7d toe881b35CompareMarch 2, 2025 13:31
@tonytonyforce-pushed thefrozen-dataclasses-custom branch frome881b35 toba0a3b9CompareMarch 2, 2025 14:57
@tonytonyforce-pushed themaster branch 3 times, most recently fromab84634 to5803841CompareApril 6, 2025 12:44
why: Fix type checking errors in the custom frozen_dataclass implementationwhat:- Added targeted mypy configuration override to disable method-assign errors- Only scoped to libtmux._internal.frozen_dataclass module- Preserves strict type checking across the rest of the codebaserefs: Enables inheritance from mutable to immutable dataclasses
…thod-assign`why: Fix type checking errors in the custom frozen_dataclass implementationwhat:- Added targeted mypy configuration override to disable method-assign errors- Only scoped to libtmux._internal.frozen_dataclass module- Preserves strict type checking across the rest of the codebaserefs: Enables inheritance from mutable to immutable dataclasses
…iles from type checkingwhy: The frozen_dataclass_sealable decorator adds attributes and methods dynamically at runtime,which mypy cannot properly analyze in test contexts, resulting in false positive errors.what:- Added mypy override to ignore type errors in tests._internal.test_frozen_dataclass_sealable- Added mypy override to ignore type errors in tests.examples._internal.frozen_dataclass_sealable.test_basic- Preserves strict typing for the implementation code while allowing tests to use dynamic featuresrefs: This addresses the mypy test failures while maintaining type safety for the implementation
…tests from strict checkingwhy:The frozen_dataclass_sealable decorator adds attributes and methods dynamicallyat runtime which causes false positive errors with static analysis tools.Testing this functionality requires patterns that deliberately violate somerules.what:- Added mypy override to ignore type errors in  tests._internal.test_frozen_dataclass_sealable- Added mypy override to ignore type errors in  tests.examples._internal.frozen_dataclass_sealable.test_basic- Added per-file ignore for RUF009 (function call in default argument) in  test_frozen_dataclass_sealable.py- Preserves strict typing and linting for implementation code while allowing  tests to use dynamic featuresrefs: This maintains code quality while acknowledging the inherentlimitations of static analysis tools when dealing with Python's dynamic runtimefeatures
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@sourcery-aisourcery-ai[bot]sourcery-ai[bot] left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Frozen dataclasses

2 participants

@tony

[8]ページ先頭

©2009-2025 Movatter.jp