Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation for python variable names #1195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpodivin
Copy link

This validation checks if string is a proper name for a python variable.

Fixes Or Enhances

Sometimes we may use our code to call external binaries, or even to construct what are effectively scripts.
Python is relatively loose, but it does enforce rules about variable names rather vehemently.
Specifically they must be generated by a specific grammar, and they must not be keywords[0].

The same restriction applies to ansible variables. So this validation may also be useful when one is constructing data structures intended to be used by ansible.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

[0] https://docs.python.org/3/reference/lexical_analysis.html#identifiers

Test cases are included.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
@jpodivin jpodivin requested a review from a team as a code owner November 10, 2023 14:59
@coveralls
Copy link

Coverage Status

coverage: 73.918% (+0.02%) from 73.903%
when pulling ade0b7f on jpodivin:python
into 84254ae on go-playground:master.

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.

None yet

2 participants