pg.typing.Str

Accessible via pg.typing.Str.

class Str(default=MISSING_VALUE, regex=None, is_noneable=False, frozen=False)[source]

Bases: pg.typing.Generic, pg.typing.PrimitiveType

Value spec for string type.

Examples:

# A required str value.
pg.typing.Str()

# A required str value which matches with a regular expression.
pg.typing.Str(regex='foo.*'))

# A str value with the default value set to 'foo'.
pg.typing.Str(default='foo')

# An optional str value with default value set to None.
pg.typing.Str().noneable()

# An optional str value with default value set to 'foo'.
pg.typing.Str(default='foo').noneable()

# A frozen str with value set to 'foo' that is not modifiable by subclasses.
pg.typing.Str().freeze('foo')

Methods:

format(*[, markdown])

Format this object.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

Attributes:

regex

Returns regular expression for acceptable values.

format(*, markdown=False, **kwargs)[source]

Format this object.

Return type:

str

property regex[source]

Returns regular expression for acceptable values.

to_json(**kwargs)[source]

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:

**kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.