Handle function defaults correctly
See original GitHub issueRight now, if you call some with function without specifying a default parameter, cache remembers it as ‘parameter not set’. If you change this default value in function definition, and call again without specifying this parameter, cache will incorrectly return the function output for the old value. Also, if you sometimes use the default and sometimes specify the value, the function will be be computed two times, needlessly.
It can be easily fixed by replacing this code: https://github.com/shaypal5/cachier/blob/5b0bff9af3dbd251ae657e4f6f27f269de977768/cachier/pickle_core.py#L152 with:
bound = inspect.signature(function).bind(*args, **kwargs)
bound.apply_defaults()
key = tuple((k, value) for k, value in sorted(bound.arguments.items()))
If you want this improvement I can do a PR.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Mind the Default Arguments in Python Functions - Medium
We assign a default value into a keyword argument is in order to make sure that the function can still work even if...
Read more >programming practices - Default values - are they good or evil?
Default values prevent stupid mistakes from the setup code. If the defaults are reasonable for most cases, fewer people mess with the working...
Read more >Default Arguments in Python Functions - Stack Abuse
Default arguments in Python functions are those arguments that take default values if no explicit values are passed to these arguments from the ......
Read more >Proper way to define default values for function arguments in ...
Since years from when I first met JavaScript I always used default values for function arguments, like:
Read more >defaultsDeep doesn't handle functions correctly #1792 - GitHub
In version 4, defaultsDeep doesn't handle assigning defaults functions in objects : 'use strict'; let _ = require('lodash'); ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ok, I opened a draft PR #50
Hey @fsondej !
Ok, I’ve set up an alternative free server on Atlas mongodb.com. All tests are now passing. You will only be able to test MongoDb core functionalities when opening a PR from your fork, as the credentials are set up on travis, and it will run all tests on a PR.
You can now continue with your good work! 😃