Skip to content

fix:get_params returns copy preventing state mutation along with adding tests#497

Open
amanpandey2587 wants to merge 1 commit intodswah:mainfrom
amanpandey2587:fix/get-params-live-dict-mutation
Open

fix:get_params returns copy preventing state mutation along with adding tests#497
amanpandey2587 wants to merge 1 commit intodswah:mainfrom
amanpandey2587:fix/get-params-live-dict-mutation

Conversation

@amanpandey2587
Copy link
Copy Markdown

@amanpandey2587 amanpandey2587 commented Mar 5, 2026

Hi @cbrummitt @fkiraly @dswah , I have made the following changes in the codebase which Closes #496

  1. I have changed core.py file attrs = self.__dict__ to attrs = dict(self.__dict__) , this prevents get_params from mutating object state during read and prevents deep=True to return a live internal dict that external callers can mutate.

  2. I have also added core-level regression tests in the pygam/tests/test_core.py and model-level regression test in pygam/tests/test_GAM_methods.py file in order to check the approach.

For Validation I ran python -m pytest pygam/tests/test_core.py pygam/tests/test_GAM_methods.py -k get_params -p no:cacheprovider to specially run the tests and I am attaching the screenshot of successfully passing them as well .
image

Please guide me for any further changes. I would be happy to do them.
Thanks

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.

Core.get_params mutates object state and returns live internal dict when deep=True

1 participant