question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle function defaults correctly

See original GitHub issue

Right 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
filypcommented, Apr 8, 2021

Ok, I opened a draft PR #50

0reactions
shaypal5commented, Apr 7, 2021

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! 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found