Repository navigation
Conversation
Two defects in the same block, both of which make a documented option unusable or inverted: * the boolean options went through bool(), so CHECK_DELIVERABILITY=false, TEST_ENVIRONMENT=0 and any other non-empty value all meant *true* - the check the user asked to turn off is the one that runs, including the DNS lookups; * DEFAULT_TIMEOUT was forwarded as a keyword argument, but validate_email has no such parameter (the real ones are timeout and the module-level DEFAULT_TIMEOUT), so setting it always ended in TypeError: validate_email() got an unexpected keyword argument 'default_timeout'. The module documents that "keyword arguments to validate_email can be set in environment variables of the same name but uppercase" and 2.0.0 added the option reading, so both spellings should mean what the docs say. The falsy set is a superset of what bool() rejected before (the empty string, plus 0/false/no/off, case- and space-insensitive), so nothing that worked changes.
|
Hi @JoshData — #175 has been open since late September with CI green, so this is the one nudge I planned. Recap: two documented CLI options are unusable, and one is inverted. The question I would most like settled, because it is the one where the README and the code disagree and I do not want to pick for you: the README documents |
Two documented CLI options are unusable, and one of them is inverted:
Both are in the same block of
email_validator/__main__.py:bool(), and since every non-empty string is truthy,CHECK_DELIVERABILITY=false/TEST_ENVIRONMENT=0/=noall mean true — the check the user asked to turn off is the one that runs, DNS lookups included;DEFAULT_TIMEOUTis collected into the same options dict and forwarded as a keyword argument, butvalidate_emailhas no such parameter. The real knobs are itstimeoutargument and the module-levelDEFAULT_TIMEOUTthatcaching_resolver()reads, so no value at all works.The module's own docstring says "keyword arguments to validate_email can be set in environment variables of the same name but uppercase", the README documents these as
check_deliverability=False, and the 2.0.0 changelog entry introduced the option reading — so both spellings are meant to work. The fix reads the falsy set explicitly (empty string, plus0/false/no/off, case- and space-insensitive), which is a superset of whatbool()used to reject, so nothing that works today changes, and it sets the module global forDEFAULT_TIMEOUT.I used
int()rather thanfloat()becauseDEFAULT_TIMEOUTis declared as anintin__init__.pyand every public timeout parameter in the library isOptional[int]— mypy rejects the float. The visible consequence is thatDEFAULT_TIMEOUT=0.5now raisesValueErrorinstead of the oldTypeError; if you would rather have fractional seconds, the consistent change is annotatingDEFAULT_TIMEOUT: floatand the timeout parameters, which is a bigger call than this PR should make on its own.Test:
pytest tests/test_main.py -k from_envfails onc0cc1bc— 13 of the 14 cases, with the DNS-failure text where the JSON is expected and theTypeErrorfor the timeout — and passes on this branch. The whole suite is 331 passed / 1 deselected (that one needs real DNS).flake8andmypyare clean.I did not add a CHANGELOG entry under "In Development" — happy to if you want one.