Skip to content

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented May 21, 2025

Description

As the title.

Issue linked

Related to #3480

Checklist

Summary by Sourcery

Enable mypy support by overhauling type hints across the codebase and cleaning up type‐ignore directives to satisfy static type checking.

Enhancements:

  • Add and refine function signatures and return type annotations (Optional, Union, List, Dict) and remove redundant TypedDict definitions
  • Standardize imports and remove over 200 # type: ignore comments for improved type safety
  • Unify command and subprocess launcher APIs by consolidating cmd argument types and simplifying submitter and launch_* functions
  • Refactor port-management utilities to accept broader input types and streamline port checking logic
  • Restructure the plotting theme module to use dynamic imports for matplotlib and PyVista and eliminate legacy fallback classes
  • Tighten type hints in command parsing and output classes for more consistent data parsing methods

@germa89 germa89 requested a review from a team as a code owner May 21, 2025 11:46
@germa89 germa89 requested review from clatapie and pyansys-ci-bot and removed request for a team May 21, 2025 11:46
@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

Copy link
Contributor

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

This PR adds mypy support by simplifying and standardizing type annotations across the codebase, removing unsupported typing constructs and type ignores, and updating function signatures and imports to enable static type checking.

Class Diagram: Removed TypedDicts in launcher.py

classDiagram
    class args_type {
        <<TypedDict (Removed)>>
        -force_intel: bool | None
        -broadcast: bool | None
        -graphics_backend: str | None
        -just_launch: bool | None
        -on_pool: bool | None
        -_debug_no_launch: bool | None
        -launch_on_hpc: bool
        -ip: str | None
        -set_no_abort: bool
        -kwargs: Dict[str, Any]
    }
    class start_parameters_type {
        <<TypedDict (Removed)>>
        -additional_switches: str | None
        -check_parameter_names: bool
        -env_vars: dict[str, str]
        -exec_file: str | None
        -finish_job_on_exit: bool
        -hostname: str | None
        -ip: str | None
        -jobid: int | None
        -jobname: str | None
        -launch_on_hpc: bool
        -launched: bool
        -mode: Literal["grpc", "console"]
        -nproc: int | bool
        -override: bool
        -port: int
        -print_com: bool
        -process: subprocess.Popen[bytes] | None
        -ram: str | None
        -run_location: str
        -start_instance: bool
        -start_timeout: int
        -timeout: int
    }
Loading

Class Diagram: Updated MapdlTheme in plotting/theme.py

classDiagram
    class Theme {
        <<PyVista Base Class>>
        font: Font
        axes: Axes
        # Other attributes/methods
    }
    class MapdlTheme {
        +__init__()
        +font.family: str
        +font.size: int
        +font.title_size: int
        +font.label_size: int
        +font.color: str
        +axes.x_color: str
        +axes.y_color: str
        +axes.z_color: str
        +cmap: Any
        +show_edges: bool
        +color: str
        +outline_color: str
        +edge_color: str
        +color_cycler: Cycler
        +render_points_as_spheres: bool
    }
    MapdlTheme --|> Theme : inherits
Loading

Class Diagram: Updated CommandOutput in commands.py

classDiagram
    class CommandOutput{
      - _cmd: Any # Type hint str | None removed
      + __new__(cls, content: str, cmd: Optional[str])
    }
Loading

Class Diagram: Updated ComponentListing in commands.py

classDiagram
    class ComponentListing{
      # _parsed() np.ndarray # property, return type changed
    }
    CommandListingOutput <|-- ComponentListing
Loading

Class Diagram: Updated Lines in convert.py

classDiagram
    class UserList_str {
      <<Old Base Class>>
    }
    class list {
      <<New Base Class>>
    }
    class Lines{
      + __init__(mute: bool)
      + append(item: Any, mute: bool = True)
      # Other list methods implicitly available
    }
    Lines --|> list
    note for Lines "Previously inherited from UserList[str]"
Loading

Class Diagram: Updated ScriptTranslator in convert.py

classDiagram
    class ScriptTranslator{
      - lines: Lines # Type is now list-based Lines
      - _functions: list # Element type unspecified
      - macros_names: list # Element type unspecified
      - _block_current_cmd: Optional[str] # Type hint simplified
      + format_using_autopep8(text: str) str # signature changed
      + save(filename: str, format_autopep8: bool = True) # signature changed
      + initialize_mapdl_object(loglevel: str, exec_file: str) # signature changed
      + store_command(function: Callable, parameters: List[str]) # signature changed, implies None return
    }
Loading

File-Level Changes

Change Details Files
Refactor launcher module to simplify typing
  • Removed TypedDict definitions and complex union/Literal annotations
  • Replaced advanced type hints with basic Optional, Union, List, Dict
  • Stripped type: ignore comments and reorganized imports
  • Updated numerous function signatures to accept simpler types and defaults
src/ansys/mapdl/core/launcher.py
Streamline plotting/theme module imports and types
  • Added try/except for optional matplotlib and pyvista imports
  • Removed legacy dataclass-based Theme fallback, replaced with minimal stub
  • Simplified colormap helpers to return numpy arrays directly
  • Cleaned up TYPE_CHECKING guards and redundant imports
src/ansys/mapdl/core/plotting/theme.py
Simplify commands module type annotations
  • Changed regex typing from Pattern[str] to untyped Pattern
  • Adjusted helper return types (indentation, sections) to List[Any]
  • Cleaned function wrappers to drop redundant typing in signatures
  • Updated table parsing methods to use simpler return types
src/ansys/mapdl/core/commands.py
Refactor convert module and Lines class
  • Replaced UserList subclass with built-in list for Lines
  • Dropped generic type parameters and simplified append/save signatures
  • Removed TypedDict and advanced typing in translate and store_command
  • Updated function signatures to basic types for mypy compatibility
src/ansys/mapdl/core/convert.py
Adjust parsing utilities and core init types
  • Simplified parse_* functions to return primitive types instead of lists
  • Removed union annotations in init.py and recalculated HAS_VISUALIZER
  • Cleaned up imports and default values for parse and init modules
src/ansys/mapdl/core/_commands/parse.py
src/ansys/mapdl/core/__init__.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!

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

@germa89 germa89 changed the base branch from maint/annotating-some-files to main May 21, 2025 11:47
@germa89
Copy link
Collaborator Author

germa89 commented May 21, 2025

@pyansys-ci-bot LGTM

@germa89 germa89 enabled auto-merge (squash) May 21, 2025 11:47
@github-actions github-actions bot added dependencies maintenance General maintenance of the repo (libraries, cicd, etc) CI/CD Related with CICD, Github Actions, etc labels May 21, 2025
Copy link
Contributor

@pyansys-ci-bot pyansys-ci-bot left a comment

Choose a reason for hiding this comment

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

✅ Approving this PR because germa89 said so in here 😬

LGTM

@github-actions github-actions bot added CI/CD Related with CICD, Github Actions, etc and removed CI/CD Related with CICD, Github Actions, etc labels May 21, 2025
@germa89 germa89 merged commit a8de41a into main May 21, 2025
87 of 88 checks passed
@germa89 germa89 deleted the ci/adding-mypy-support branch May 21, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD Related with CICD, Github Actions, etc dependencies maintenance General maintenance of the repo (libraries, cicd, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants