Validation

flutils offers the following validation functions.

validate_identifier(identifier, allow_underscore=True)[source]

Validate the given string is a proper identifier.

This validator will also raise an error if the given identifier is a keyword or a builtin identifier.

Parameters
  • identifier (str or UserString) – The value to be tested.

  • allow_underscore (bool, optional) – A value of False will raise an error when the identifier has a value that starts with an underscore _. (Use False when validating potential namedtuple keys) Defaults to: True.

Raises
Return type

None

Example

>>> from flutils.validators import validate_identifier
>>> validate_identifier('123')
SyntaxError: The given 'identifier', '123', cannot start with a number