Skip to content

Include os.PathLike when typing path parameters - #940

Merged
benkiel merged 5 commits into
robotools:devfrom
adbac:improve-path-typing
Jul 9, 2026
Merged

Include os.PathLike when typing path parameters#940
benkiel merged 5 commits into
robotools:devfrom
adbac:improve-path-typing

Conversation

@adbac

@adbac adbac commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

In order to pass pathlib.Path objects to the __init__ and save methods of font objects, this PR adds os.PathLike to the type hints of path parameters.

Currently, only RFont._init types pathOrObject this way, which means it isn't picked up by static type checkers when initializing objects.

@adbac
adbac changed the base branch from main to dev July 6, 2026 08:40
@adbac

adbac commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Should we update the normalizeFilePath function signature to accept os.PathLike too? mypy checks fail on this point only.

@benkiel

benkiel commented Jul 6, 2026

Copy link
Copy Markdown
Member

@knutnergaard you are the typing guru here, thoughts?

@knutnergaard

Copy link
Copy Markdown
Contributor

On vacation, so can't check, but the pathlib.Path annotation in normalizeFilePath is likely too strict, and should be changed to os.pathLike.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.69%. Comparing base (4c387ec) to head (70e6b92).
⚠️ Report is 5 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #940   +/-   ##
=======================================
  Coverage   86.69%   86.69%           
=======================================
  Files          43       43           
  Lines        6727     6728    +1     
  Branches      972      972           
=======================================
+ Hits         5832     5833    +1     
  Misses        694      694           
  Partials      201      201           
Files with missing lines Coverage Δ
Lib/fontParts/base/font.py 94.78% <100.00%> (ø)
Lib/fontParts/base/normalizers.py 98.96% <100.00%> (+<0.01%) ⬆️
Lib/fontParts/fontshell/font.py 92.85% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adbac

adbac commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Strange type checking error here, mypy still considers path to be of type str | Any | PathLike[Any] after calling os.path.splitext. splitext can only return a tuple of strings, right?

path = os.path.splitext(self.path)[0]
path += ext

@benkiel

benkiel commented Jul 7, 2026

Copy link
Copy Markdown
Member

@adbac As far as I can tell, yes, but clearly mypy disagrees...

@knutnergaard

knutnergaard commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Strange type checking error here, mypy still considers path to be of type str | Any | PathLike[Any] after calling os.path.splitext. splitext can only return a tuple of strings, right?

I think it might return a tuple of bytes as well, depending on the input type. Converting path to string should do it.

@benkiel

benkiel commented Jul 9, 2026

Copy link
Copy Markdown
Member

Hey @adbac This is not just a ruff formatting check, I'll run that and review!

@benkiel
benkiel merged commit 3c35030 into robotools:dev Jul 9, 2026
12 of 13 checks passed
benkiel added a commit that referenced this pull request Jul 9, 2026
* Fix release (#936)

* Update Readme

* Update .gitignore

* Rework publishing

* fixup

* Fix release (#937)

* Update Readme

* Update .gitignore

* Rework publishing

* fixup

* Control how version number is constructed

* Control how version number is constructed

* Update pyproject.toml

* Fix

* Fixup

* Update NEWS

* Dropping test.pypi.org. Version number will be hell to sort

* Include `os.PathLike` when typing path parameters (#940)

* update type hints for paths to use os.PathLike

* update path type hints in generate methods

* make RFont._save path type hint compatible with superclass

* widen type parameter type in normalizeFilePath function

* call os.fsdecode on path to get a string object

* Ruff formatting run (#941)

* Update News for release

---------

Co-authored-by: Adrien Bachelart <126618591+adbac@users.noreply.github.com>
@adbac

adbac commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

@adbac
adbac deleted the improve-path-typing branch July 9, 2026 18:48
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.

3 participants