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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.