Accept os.PathLike wherever a str path is accepted#2064
Open
HaozheZhang6 wants to merge 1 commit into
Open
Conversation
Every exporter and importer entry point took str only, so passing a
pathlib.Path raised AttributeError ('PosixPath' object has no attribute
'split') or a TypeError from the OCP/VTK call underneath.
Widen the annotations to str | os.PathLike[str] and normalize with
os.fspath() where the value reaches a string operation, OCCT, or VTK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2016.
Passing a
pathlib.Pathto any of the IO entry points fails today:Annotations are widened to
str | os.PathLike[str](PathLikeincadquery/types.py), and the value is normalized withos.fspath()where it reaches a string operation, OCCT or VTK. Functions that only forward the path are left to the callee to normalize.Covered:
exporters.export,exportSVG,exportDXF,exportVTP,exportAssembly,exportStepMeta,exportCAF,exportVTKJS,exportVRML,exportGLTF,importShape,importStep,importDXF,importBrep,importBin, the assembly importers,Shape.export*/import*,Workplane.export/exportSvg,Sketch.export/importDXF,Assembly.save/export/load/importStep.Shape.exportBrep/importBrep/exportBin/importBinalso take aBytesIO, so those go through a small_fspathhelper that passes file objects through untouched.Tests:
test_export_pathlike(every formatexporters.exportsupports, plus theShape/Workplane/Sketchmethods),TestImporters.testPathLike, andtest_pathlikein the assembly tests. All three fail on master with theAttributeErrorabove.