Attrs' type annotations do not validate or enforce types. This can result in certain parameters such as DataSource.client_id_column being typed as as str, but being None at runtime. This issue proposes enforcing runtime types using attrs' validator & converter methods. For example:
class DataSource:
...
client_id_column = attr.ib(
default="client_id" # if nothing is passed to DataSource.__init__
type=str,
validator=[attr.validators.instance_of(str), attr.validators.min_len(1)],
converter=attr.converters.default_if_none("client_id")
# ^ handles case where `client_id_column = None` passed to DataSource.__init__
)
This will allow callers to instantiate a data source object by passing nothing, a None, or a str as the client_id_column parameter.
Attrs' type annotations do not validate or enforce types. This can result in certain parameters such as
DataSource.client_id_column
being typed as as str, but beingNone
at runtime. This issue proposes enforcing runtime types using attrs' validator & converter methods. For example:This will allow callers to instantiate a data source object by passing nothing, a
None
, or astr
as theclient_id_column
parameter.