Skip to content

Fix all mypy strict mode errors#23

Merged
eman merged 18 commits intomainfrom
mypy-strict-fixes
Oct 20, 2025
Merged

Fix all mypy strict mode errors#23
eman merged 18 commits intomainfrom
mypy-strict-fixes

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Oct 19, 2025

Summary

Fixed all 170 mypy strict mode errors across 23 source files

Changes Made

Type Annotations

  • Added explicit return type annotations (-> None) to all inner callback functions
  • Fixed Callable type parameters with full signatures
  • Added int() casts for AWS IoT SDK packet_id returns
  • Fixed Optional[str] handling in mqtt_client.py

Code Structure

  • Reorganized CLI into modular package structure (cli/init.py, cli/main.py, etc.)
  • Split monolithic cli.py into focused modules: commands.py, monitoring.py, output_formatters.py, token_storage.py
  • Moved imports to correct modules (MqttConnectionConfig, PeriodicRequestType)

Bug Fixes

  • Fixed unreachable code after asyncio.sleep() calls
  • Removed duplicate class definitions
  • Fixed shadowing of 'args' parameter in CLI
  • Commented out non-existent method reference (request_device_feature)

Testing

  • All 35 tests passing
  • No functional regressions
  • Code coverage maintained at 27%

Files Modified

  • Core: init.py, api_client.py, models.py
  • CLI: Reorganized into cli/ package
  • MQTT: mqtt_client.py + 7 new modular files
  • Tests: test_utils.py (new)

Verification

# Mypy check
python -m mypy src/nwp500
# Result: Success: no issues found in 23 source files

# Tests
python -m pytest tests/ -v
# Result: 35 passed, 6 warnings

- Fixed 170 mypy strict mode errors across 23 source files
- Added explicit type annotations for all callback functions
- Fixed Optional[str] handling in mqtt_client.py
- Added int() casts for AWS IoT packet_id returns
- Reorganized CLI into modular package structure
- Moved imports to correct modules (MqttConnectionConfig, PeriodicRequestType)
- Fixed unreachable code and duplicate definitions
- All 35 tests passing
- Updated copilot instructions with communication preferences
eman and others added 3 commits October 18, 2025 22:41
- Remove unused variable in mqtt_client.py
- Fix line length issues (split long lines)
- Remove unused import (Protocol)
- Format with ruff
…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
eman and others added 2 commits October 18, 2025 22:51
…sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Removed import of topic_has_mac which doesn't exist in mqtt_utils
- Simplified logging to just use redact_topic everywhere
- All mypy and linting checks now pass
eman and others added 2 commits October 18, 2025 22:59
…sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@eman eman requested a review from Copilot October 19, 2025 06:02
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 fixes all 170 mypy strict mode errors across 23 source files by adding comprehensive type annotations, reorganizing code structure, and eliminating dead code. The changes maintain backward compatibility while significantly improving type safety.

Key changes:

  • Added explicit return type annotations (-> None) to callback functions
  • Fixed Callable type parameters with complete signatures
  • Reorganized CLI into modular package (cli/init.py, cli/main.py, etc.)
  • Created new utility modules: mqtt_utils.py, encoding.py, utils.py
  • Split monolithic mqtt_client.py into focused components

Reviewed Changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_utils.py New test file for log_performance decorator utility
tests/test_command_queue.py Updated import path for QueuedCommand after refactoring
tests/test_api_helpers.py Updated imports to use new encoding module
test_api_connectivity.py New API connectivity test script
src/nwp500/utils.py New utility module with log_performance decorator
src/nwp500/py.typed Added PEP 561 marker for type checking support
src/nwp500/mqtt_utils.py Extracted MQTT utilities (redaction, config, types)
src/nwp500/mqtt_subscriptions.py Extracted subscription management logic
src/nwp500/mqtt_reconnection.py Extracted reconnection handler logic
src/nwp500/mqtt_periodic.py Extracted periodic request manager
src/nwp500/mqtt_device_control.py Extracted device control commands
src/nwp500/mqtt_connection.py Extracted connection management
src/nwp500/mqtt_command_queue.py Extracted command queue management
src/nwp500/mqtt_client.py Refactored to delegate to specialized components
src/nwp500/models.py Improved field conversions with metadata approach
src/nwp500/events.py Enhanced type annotations and frozen dataclass
src/nwp500/encoding.py New module for encoding/decoding utilities
src/nwp500/constants.py Converted to IntEnum with backward compatibility
src/nwp500/cli/* Reorganized into modular package structure
src/nwp500/init.py Updated exports for new module structure

eman and others added 5 commits October 18, 2025 23:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@eman eman requested a review from Copilot October 19, 2025 23:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 2 comments.

eman and others added 2 commits October 19, 2025 16:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@eman eman merged commit 13aba28 into main Oct 20, 2025
10 checks passed
@eman eman deleted the mypy-strict-fixes branch October 20, 2025 00:45
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.

2 participants