Idea how to clean up the parameter list of validate_email[_or_fail] #56

Closed
opened 2021-02-22 15:16:40 +01:00 by reinhard-mueller · 0 comments
reinhard-mueller commented 2021-02-22 15:16:40 +01:00 (Migrated from github.com)

With the growing number of checks that can be switched on and off, the parameter list has become somewhat long and cluttered, switches are named use_*, check_*, or skip_*, and also some have to be set to True to enable a test, some to True to disable the test.

I had the idea of replacing all these parameters with a single one:

First, we define a constant for each of the possible checks:

CHECK_FORMAT = 1
CHECK_BLACKLIST = 2
CHECK_MX = 3
CHECK_SMTP = 4
CHECK_SMTP_COMMUNICATION = 5
CHECK_SMTP_TEMPORARY = 6

and we define the default set of checks as a Python set:

CHECK_DEFAULT = {CHECK_FORMAT, CHECK_BLACKLIST, CHECK_MX, CHECK_SMTP}

Then, we can change validate_email_or_fail to accept the parameter checks: Set = CHECK_DEFAULT.

Downside: this would either break compatibility with previous versions, or we'd have to accept both options for a while, adding a deprecation warning when the old parameters are used.

What do you think?

With the growing number of checks that can be switched on and off, the parameter list has become somewhat long and cluttered, switches are named `use_*`, `check_*`, or `skip_*`, and also some have to be set to `True` to enable a test, some to `True` to disable the test. I had the idea of replacing all these parameters with a single one: First, we define a constant for each of the possible checks: ```python CHECK_FORMAT = 1 CHECK_BLACKLIST = 2 CHECK_MX = 3 CHECK_SMTP = 4 CHECK_SMTP_COMMUNICATION = 5 CHECK_SMTP_TEMPORARY = 6 ``` and we define the default set of checks as a Python `set`: ```python CHECK_DEFAULT = {CHECK_FORMAT, CHECK_BLACKLIST, CHECK_MX, CHECK_SMTP} ``` Then, we can change `validate_email_or_fail` to accept the parameter `checks: Set = CHECK_DEFAULT`. Downside: this would either break compatibility with previous versions, or we'd have to accept both options for a while, adding a deprecation warning when the old parameters are used. What do you think? ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: karolyi/py3-validate-email#56
No description provided.