Skip to content

Conversation

@mdevolde
Copy link
Collaborator

@mdevolde mdevolde commented Nov 18, 2025

refactor: replaced os.path uses by pathlib

Why the pull request was made

This PR replaces all usage of os.path with pathlib.Path, the modern and recommended API for filesystem path handling.

Summary of changes

  • Replaced os.unlink and os.remove by Path().unlink
  • Replaced str returns by Path returns
  • Replaced os.makedirs by Path().mkdirs
  • Replaced os.path.isdir by Path().is_dir
  • Replaced os.path.isfile by Path().is_file
  • Replaced os.path.splitext by Path().name and Path().stem
  • Replaced os.path.join by / operator
  • Corrected a bug to choose the latest installed LT version

Screenshots (if appropriate):

Not applicable.

How has this been tested?

Applied local tests, prints.

Resources

Not applicable.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation only)
  • Refactor / code style update (non-breaking change that improves code structure or readability)
  • Tests / CI improvement (adding or updating tests or CI configuration only)
  • Other (please describe):

Checklist

  • Followed the project's contributing guidelines.
  • Updated any relevant tests.
  • Updated any relevant documentation.
  • Added comments to your code where necessary.
  • Formatted your code, run the linters, checked types and tests.
Copy link
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 refactors the codebase to use pathlib.Path instead of os.path for filesystem operations, modernizing the path handling approach. The changes include updating return types from str to Path, replacing path concatenation with the / operator, and introducing a new version extraction function that uses semantic versioning.

Key Changes:

  • Migrated from os.path operations to pathlib.Path methods across the codebase
  • Updated function signatures to return Path objects instead of strings
  • Introduced _extract_version() function with semantic version comparison for finding latest LanguageTool installation

Reviewed Changes

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

Show a summary per file
File Description
language_tool_python/utils.py Converted path handling to pathlib; added version extraction function; updated return types to Path
language_tool_python/server.py Migrated spelling file path construction to use pathlib Path division operator
language_tool_python/download_lt.py Updated function signatures to accept Path parameters; replaced os.remove with Path.unlink
language_tool_python/config_file.py Replaced os.unlink with Path.unlink for temporary file cleanup
tests/test_major_functionality.py Updated test to use pathlib Path division operator for path construction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
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 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mdevolde mdevolde requested a review from Copilot November 18, 2025 16:46
@mdevolde mdevolde merged commit 22551c8 into jxmorris12:master Nov 18, 2025
14 checks passed
@mdevolde mdevolde deleted the pathlib branch November 18, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant