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

Add __all__ to more files #594

Merged
merged 8 commits into from
Jan 30, 2025
Merged

Add __all__ to more files #594

merged 8 commits into from
Jan 30, 2025

Conversation

MatthewMckee4
Copy link
Member

@MatthewMckee4 MatthewMckee4 commented Jan 30, 2025

Summary by Sourcery

Enhance module encapsulation by adding all declarations to various files, refactor type annotations to use new type aliases AnyKCell and AnyTKCell, and simplify error handling in switch cases.

Enhancements:

  • Add all declarations to multiple files to explicitly define public interfaces and improve module encapsulation.
  • Refactor type annotations to use new type aliases AnyKCell and AnyTKCell for better code clarity and maintainability.
  • Simplify error handling by replacing specific error messages with ellipses in certain switch cases.

Copy link
Contributor

sourcery-ai bot commented Jan 30, 2025

Reviewer's Guide by Sourcery

This pull request adds all declarations to multiple files to control module exports, refactors type aliasing and type hinting for improved clarity and type safety, and simplifies error handling using match-case statements.

Class diagram showing updated type hierarchy for ProtoKCell and related classes

classDiagram
    class GeometricObject~TUnit~ {
        <<abstract>>
        +kcl: KCLayout
        +bbox(layer: int|None): BoxLike~TUnit~
        +transform(trans: Trans|DTrans|ICplxTrans|DCplxTrans)
    }
    class ProtoKCell~TUnit,TBaseCell~ {
        <<abstract>>
        -_base_kcell: TBaseCell
        +locked: bool
    }
    class ProtoTKCell~TUnit~ {
        <<abstract>>
    }
    class VKCell {
        -_shapes: dict[int, VShapes]
        -_name: str|None
    }

    GeometricObject <|-- ProtoKCell
    ProtoKCell <|-- ProtoTKCell
    ProtoKCell <|-- VKCell

    note for ProtoKCell "Updated to use generic TBaseCell"
Loading

Class diagram showing updated type aliases and relationships

classDiagram
    class AnyKCell {
        <<type alias>>
    }
    class AnyTKCell {
        <<type alias>>
    }
    class ProtoKCell
    class ProtoTKCell

    AnyKCell .. ProtoKCell : ProtoKCell[Any, Any]
    AnyTKCell .. ProtoTKCell : ProtoTKCell[Any]

    note for AnyKCell "New type alias for generic ProtoKCell"
Loading

File-Level Changes

Change Details Files
Added all declarations to multiple files for better module export control.
  • Added all to kcell.py with new exports.
  • Added all to ports.py with new exports.
  • Added all to instance_ports.py with new exports.
  • Added all to instance.py with new exports.
  • Added all to layout.py with new exports.
  • Added all to exceptions.py with new exports.
  • Added all to geometry.py with new exports.
  • Added all to layer.py with new exports.
  • Added all to conf.py with new exports.
  • Added all to instance_group.py with new exports.
  • Added all to instances.py with new exports.
  • Added all to shapes.py with new exports.
  • Added all to grid.py with new exports.
  • Added all to merge.py with new exports.
  • Added all to packing.py with new exports.
  • Added all to protocols.py with new exports.
  • Added all to settings.py with new exports.
src/kfactory/kcell.py
src/kfactory/ports.py
src/kfactory/instance_ports.py
src/kfactory/instance.py
src/kfactory/layout.py
src/kfactory/exceptions.py
src/kfactory/geometry.py
src/kfactory/layer.py
src/kfactory/conf.py
src/kfactory/instance_group.py
src/kfactory/instances.py
src/kfactory/shapes.py
src/kfactory/grid.py
src/kfactory/merge.py
src/kfactory/packing.py
src/kfactory/protocols.py
src/kfactory/settings.py
Refactored type aliasing and type hinting for better code clarity and type safety.
  • Replaced ProtoTKCell[Any] with AnyTKCell in multiple function signatures.
  • Replaced ProtoKCell[Any] with AnyKCell in multiple function signatures.
  • Introduced new type aliases AnyKCell and AnyTKCell in kcell.py.
  • Updated type hints in ports.py to use TPort instead of Port.
  • Updated type hints in instance_ports.py to use TInstance.
  • Updated type hints in instance.py to use AnyKCell and AnyTKCell.
  • Updated type hints in layout.py to use AnyTKCell.
  • Updated type hints in conf.py to use AnyKCell.
  • Updated type hints in port.py to use AnyTKCell.
  • Updated type hints in serialization.py to use AnyKCell.
  • Updated type hints in placer.py to use AnyTKCell.
  • Updated type hints in interactive.py to use ProtoKCell[Any, Any].
src/kfactory/kcell.py
src/kfactory/ports.py
src/kfactory/instance_ports.py
src/kfactory/instance.py
src/kfactory/layout.py
src/kfactory/conf.py
src/kfactory/port.py
src/kfactory/serialization.py
src/kfactory/placer.py
src/kfactory/widgets/interactive.py
Simplified error handling and control flow using match-case statements.
  • Replaced specific error handling with match-case in kcell.py.
  • Replaced specific error handling with match-case in instance.py.
src/kfactory/kcell.py
src/kfactory/instance.py

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 your dashboard 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

@github-actions github-actions bot added the enhancement New feature or request label Jan 30, 2025
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.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

@@ -766,15 +772,15 @@ def insert_into_flat(
@overload
def insert_into_flat(
self,
cell: ProtoTKCell[Any] | VKCell,
cell: AnyKCell,
*,
trans: kdb.DCplxTrans | None = None,
levels: int,
) -> None: ...

def insert_into_flat(
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:


Explanation

The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 75.26882% with 23 lines in your changes missing coverage. Please review.

Project coverage is 63.61%. Comparing base (2d6c317) to head (cd99357).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/kfactory/port.py 20.00% 7 Missing and 1 partial ⚠️
src/kfactory/ports.py 61.11% 6 Missing and 1 partial ⚠️
src/kfactory/instance.py 69.23% 4 Missing ⚠️
src/kfactory/kcell.py 78.57% 3 Missing ⚠️
src/kfactory/utilities.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #594      +/-   ##
==========================================
+ Coverage   63.50%   63.61%   +0.11%     
==========================================
  Files          64       64              
  Lines        9573     9561      -12     
  Branches     1785     1777       -8     
==========================================
+ Hits         6079     6082       +3     
+ Misses       2943     2928      -15     
  Partials      551      551              

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

@MatthewMckee4 MatthewMckee4 merged commit 966e95d into main Jan 30, 2025
16 checks passed
@MatthewMckee4 MatthewMckee4 deleted the exports branch January 30, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants