Skip to content

refactor: update function signatures to accept both str and Path types#187

Merged
davidberenstein1957 merged 9 commits intoPrunaAI:mainfrom
Ayyanaruto:feat/pathlib-support-save-load
Jun 24, 2025
Merged

refactor: update function signatures to accept both str and Path types#187
davidberenstein1957 merged 9 commits intoPrunaAI:mainfrom
Ayyanaruto:feat/pathlib-support-save-load

Conversation

@Ayyanaruto
Copy link
Copy Markdown
Contributor

@Ayyanaruto Ayyanaruto commented Jun 8, 2025

Description

This pull request enhances type flexibility across multiple files by replacing str with Union[str, Path] for file path parameters. This change enables functions to accept both string-based paths and Path objects from the pathlib module, improving compatibility and usability. The pathlib.Path module has also been imported wherever necessary.

Related Issue

Fixes #49

Linked Pruna Pro PR: https://github.com/PrunaAI/prunatree/pull/129

Type of Change

  • Added type flexibility to support both Path and str for file-related parameters in save and load functions
  • Modified type annotations in files such as save.py, load.py, smash_config.py, and utils.py

How Has This Been Tested?

  • Unit tests run:

    • test_save.py
    • test_load.py

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@davidberenstein1957
Copy link
Copy Markdown
Member

davidberenstein1957 commented Jun 9, 2025

@Ayyanaruto , thanks for the great helpt. Could you add tests for this?

@Ayyanaruto
Copy link
Copy Markdown
Contributor Author

Hey @davidberenstein1957 sure 😄 !

Copy link
Copy Markdown
Member

@davidberenstein1957 davidberenstein1957 left a comment

Choose a reason for hiding this comment

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

Hii looks good! Would you be able to use the | operator instead of the Union? Additionally, could you add something like test_deprecation_* to cover the old behavior ?

Comment thread src/pruna/engine/save.py Outdated
Comment thread src/pruna/engine/save.py Outdated
Comment thread src/pruna/engine/save.py Outdated
@Ayyanaruto
Copy link
Copy Markdown
Contributor Author

Hii looks good! Would you be able to use the | operator instead of the Union? Additionally, could you add something like test_deprecation_* to cover the old behavior ?

Sure @davidberenstein1957 , Can you elaborate what you mean by > "Additionally, could you add something like test_deprecation_* to cover the old behavior" , By old behaviour you mean where we were using paths type as str

@Ayyanaruto Ayyanaruto force-pushed the feat/pathlib-support-save-load branch from 5423dec to b69b70a Compare June 10, 2025 17:14
@davidberenstein1957 davidberenstein1957 self-requested a review June 10, 2025 18:57
@davidberenstein1957
Copy link
Copy Markdown
Member

@Ayyanaruto there is a tiny error where we should convert the path to string before passing it to the underlying method. Could you fix that?

Comment thread tests/engine/test_load.py Outdated
Comment thread tests/engine/test_load.py Outdated
@Ayyanaruto
Copy link
Copy Markdown
Contributor Author

@Ayyanaruto there is a tiny error where we should convert the path to string before passing it to the underlying method. Could you fix that?

Hey @davidberenstein1957, sure! I’m in college at the moment, so I’ll need a little time. I’ll get it fixed as soon as I’m free.

@Ayyanaruto Ayyanaruto force-pushed the feat/pathlib-support-save-load branch from b3333d4 to ea969e1 Compare June 11, 2025 15:42
@Ayyanaruto
Copy link
Copy Markdown
Contributor Author

Hi @davidberenstein1957 Apologies for the delay I was a bit busy today. Thank you for always reviewing my PRs and for your continued help and support

Copy link
Copy Markdown
Member

@davidberenstein1957 davidberenstein1957 left a comment

Choose a reason for hiding this comment

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

LFTM

@davidberenstein1957
Copy link
Copy Markdown
Member

davidberenstein1957 commented Jun 18, 2025

Hi @Ayyanaruto, could you rebase on main? Somethign like the following should work.

  • git checkout main
  • git pull
  • git checkout feat/pathlib-support-save-load
  • git rebase main and resolve conflicts
  • git push --force

@Ayyanaruto
Copy link
Copy Markdown
Contributor Author

Oh thanks, sorry for responding late

Comment thread src/pruna/engine/load.py Outdated
Comment thread src/pruna/engine/load.py Outdated
Comment thread src/pruna/engine/load.py Outdated
Comment thread src/pruna/engine/save.py Outdated
Comment thread tests/engine/test_load.py Outdated
@davidberenstein1957 davidberenstein1957 merged commit 28345c1 into PrunaAI:main Jun 24, 2025
3 checks passed
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.

[FEATURE] add Path support to save and load methods

3 participants