-
Notifications
You must be signed in to change notification settings - Fork 140
fix: mypy type checking issues across core modules #4309
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
base: main
Are you sure you want to change the base?
Conversation
…n bracket_static example
…command mixins inherit Add a CommandsBase class (with a typed run(command, write_to_log, mute, **kwargs) stub) to declare the interface used by APDL command mixins. Update numerous command modules to import and inherit from CommandsBase so mixins consistently express the expected run() contract for the parent MAPDL class.
…otations Convert several Literal tuple usages to explicit TypeAlias (ENTITIES_TYP, RESIDUAL_ALGORITHM_LITERAL, VALID_DEVICES_LITERAL, VALID_FILE_TYPE_FOR_PLOT_LITERAL), import TypeAlias where needed, and add typing annotations for base_report_class. Minor typing cleanup and ignore-type for Report subclassing.
- common_grpc: annotate parse_chunks as grpc.CallIterator (ignore name-defined) - component: correct ENTITIES_MAPPING typing, tighten Component __new__/repr/type signatures and add attr type ignores - helpers: fix namedtuple import from collections - krylov: guard residuals with None check and add attr type ignore on append - logging: add type ignores for dynamic logger handler attributes - mapdl_core: fix mesh check (grid.n_node), accept pathlib.Path in _decompose_fname, add asserts for newly created/opened resources, and local rename for clarity - mapdl_geometry: allow ndarray for _select_items parameter - misc: broaden routine parameters to accept str or ROUTINES and add type ignores for mapdl attribute access - pool: avoid shadowing timeout by renaming and add type ignore for progress bar update These changes improve typing correctness, silence false-positive type errors, and address several small bugs/clarifications.
… core modules - component: broaden Component.__new__ to accept lists, ndarrays, ints, strs, Components and None; coerce items to tuple and handle fallbacks. Make ComponentManager handle cmtype as string or [selection, type] and guard cmlist parsing for None. - krylov: tighten typing (Optional[str] for full_file), accept int/str for frequency inputs, allow residual_algorithm to be Optional and validate only when provided. - licensing: raise OSError when home directory cannot be determined before building license path. - mapdl_core: accept pathlib.Path or str in _wrap_directory. - mapdl_extended / mapdl_grpc: add targeted type ignores and refine parameter types (chunk_size, progress_bar, _mapdl_process, vget/nvar, VAR_IR) to satisfy static typing and avoid mypy issues. - misc: robust MODULE_PATH resolution using inspect.currentframe() with fallback to __file__.
…arent/type guards - component: refine __getitem__ return annotation to Component (type: ignore[override]) - krylov: guard residual_algorithm against None before calling .lower() - licensing: handle missing subprocess.stdout, ensure licenses is a list, and check output type before searching for error messages - logging: check self.extra is not None before accessing .name - mapdl_core: cache parent reference in WithInterativePlotting and assert it's not None; avoid repeated _parent() calls - mapdl_extended: safely search for the table block before parsing and only populate the table if a match is found - mapdl_grpc: return empty string instead of None from command response helper - mesh_grpc: use safe regex matches when extracting REAL CONSTANT SET, ITEMS, and TO values - parameters: guard regex searches when extracting parameter names and string elements to avoid AttributeError
- fix Literal alias declaration in common_grpc - tighten Optional/Union signatures and use TypeAlias where appropriate - add explicit variable typings and where necessary - small parsing/type improvements in component, parameters, misc - annotate/adjust dynamic fields in mapdl_core, mapdl_grpc, licensing, pool, krylov, logging Improve type clarity and runtime robustness while keeping dynamic assignments compatible with runtime values.
Add/adjust type hints (TextIO, Optional, list[str], TYPE_CHECKING imports), tighten function signatures, add targeted type:ignore comments, cast query results to int for SelectionStatus, and improve internal type checks/assertions. Also rename a few tests for clearer descriptions.
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 addresses mypy type checking issues across PyMAPDL core modules, reducing type errors from 132 to 0. The changes primarily involve adding type annotations, fixing type mismatches, and adding explicit type ignore comments where needed for compatibility with dynamic MAPDL operations.
Key changes include:
- Added proper type annotations for class attributes and function parameters
- Fixed Optional type annotations and None handling
- Added type ignore comments for intentional dynamic typing patterns
- Made all command mixin classes inherit from
CommandsBasefor proper type checking
Reviewed Changes
Copilot reviewed 149 out of 149 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_licensing.py | Changed exception handler to use pass instead of assigning None to bool |
| tests/test_geometry.py | Renamed duplicate test names for uniqueness |
| tests/test_console.py | Renamed duplicate test names for uniqueness |
| src/ansys/mapdl/core/report.py | Added Type annotation for base_report_class and type ignore for dynamic inheritance |
| src/ansys/mapdl/core/pool.py | Fixed Optional type hints and timeout handling logic |
| src/ansys/mapdl/core/plotting/visualizer.py | Added Optional type hints for parameters and None checks |
| src/ansys/mapdl/core/plotting/init.py | Removed incorrect type annotations from enum values |
| src/ansys/mapdl/core/parameters.py | Added type ignore comments for intentional mixed dict types |
| src/ansys/mapdl/core/misc.py | Fixed inspect.currentframe() None handling and type annotations |
| src/ansys/mapdl/core/mesh_grpc.py | Added None checks for regex matches and cast float to int |
| src/ansys/mapdl/core/mapdl_grpc.py | Added stub None checks and fixed attribute type annotations |
| src/ansys/mapdl/core/mapdl_geometry.py | Fixed type annotations for Union with np.ndarray |
| src/ansys/mapdl/core/mapdl_extended.py | Added None checks for regex matches and type ignore comments |
| src/ansys/mapdl/core/mapdl_core.py | Added TextIO and TypeAlias imports, fixed Literal definitions |
| src/ansys/mapdl/core/logging.py | Added type ignore comments for dynamic logger attributes |
| src/ansys/mapdl/core/licensing.py | Fixed type annotations for Optional parameters and list assignments |
| src/ansys/mapdl/core/krylov.py | Added type ignore comments for dynamic MAPDL parameter operations |
| src/ansys/mapdl/core/helpers.py | Removed invalid namedtuple return type annotation |
| src/ansys/mapdl/core/examples/verif_files.py | Added None check for inspect.currentframe() |
| src/ansys/mapdl/core/database/database.py | Added None check for environment variable access |
| src/ansys/mapdl/core/component.py | Fixed Component type annotations and conversion logic |
| src/ansys/mapdl/core/common_grpc.py | Replaced None with empty string in list items |
| src/ansys/mapdl/core/commands.py | Added value parameter to property setter |
| src/ansys/mapdl/core/cli/convert.py | Changed file parameters to TextIO type |
| src/ansys/mapdl/core/_commands/solution/*.py | Added CommandsBase inheritance to all solution command classes |
| src/ansys/mapdl/core/_commands/session/*.py | Added CommandsBase inheritance to all session command classes |
| src/ansys/mapdl/core/_commands/preproc/*.py | Added CommandsBase inheritance to all preproc command classes |
| src/ansys/mapdl/core/_commands/post26/*.py | Added CommandsBase inheritance to all post26 command classes |
| src/ansys/mapdl/core/_commands/post1/*.py | Added CommandsBase inheritance to all post1 command classes |
| src/ansys/mapdl/core/_commands/graphics/*.py | Added CommandsBase inheritance to all graphics command classes |
| src/ansys/mapdl/core/_commands/init.py | Added CommandsBase class definition with run method interface |
| pyproject.toml | Added mypy exclusions and configuration options |
| .pre-commit-config.yaml | Added doc/ and examples/ exclusions to mypy hook |
| .ci/pytest_summary.py | Added type ignore comments for union type operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # rare bug | ||
| if grid is not None: | ||
| if grid.n_points != self._archive_cache.n_node: | ||
| if grid.n_node != self._archive_cache.n_node: |
Copilot
AI
Nov 18, 2025
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.
Incorrect attribute name. Should be grid.n_points not grid.n_node. The VTK grid object uses n_points as shown in the comment on line 1320.
| if grid.n_node != self._archive_cache.n_node: | |
| if grid.n_points != self._archive_cache.n_node: |
| <SelectionStatus.UNDEFINED: 0> | ||
| """ | ||
| return SelectionStatus(self._run_query(f"KSEL({k})", integer=True)) | ||
| return SelectionStatus(int(self._run_query(f"KSEL({k})", integer=True))) |
Copilot
AI
Nov 18, 2025
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.
Redundant int() conversions. The _run_query method is already called with integer=True, which should return an int. The explicit int() cast is unnecessary and suggests the return type of _run_query should be fixed instead.
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
…ing import, and update docstring
…to fix/mypy-errors
Description
This PR resolves mypy type checking issues across the PyMAPDL core modules, reducing errors from 132 to 0 in source code.
Changes
Type Annotations & Fixes
Configuration
Testing
Impact