Skip to content

Conversation

breuleux
Copy link
Collaborator

@breuleux breuleux commented Aug 5, 2021

This adds a strict argument to varname, register and Wrapper that requires a direct assignment to the variable. In other words:

def function(strict):
    return varname(strict=strict)

func = function(True)     # OK, direct assignment, func == 'func'

func = [function(True)]   # Not a direct assignment, raises ImproperUseError
func = [function(False)]  # OK, func == ['func']

func = function(False), function(False)   # OK, func = ('func', 'func')

Insofar that the plan is for strict to default to True starting in 0.8.0, when strict is not given and the assignment is not direct, the old behavior is preserved but displays a deprecation warning.

Supersedes #56

@pwwang pwwang merged commit 36a2993 into pwwang:dev Aug 5, 2021
@pwwang pwwang mentioned this pull request Aug 10, 2021
pwwang added a commit that referenced this pull request Aug 10, 2021
* Add strict mode to varname (#57)

* Update CI configuration so that it can be triggered in PR by assign and label.

* Support the walrus operator (:=) (#58)

* Prepare 0.7.2
- Update README to add breuleux as contributor
- Don't upload coverage in CI with PRs
- Update some docs for varname()

* 0.7.2

Co-authored-by: Olivier Breuleux <breuleux AT gmail.com>
@pwwang pwwang mentioned this pull request Aug 13, 2021
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.

2 participants