[MAINTENANCE] Type-check tests/datasource/
Part of #12128.
What to do
Bring the three excluded paths under tests/datasource/ into the type-check: fix the 30 errors
mypy reports there, then remove the three covering exclude patterns from pyproject.toml and
regenerate the relaxation inventory in the same change.
Fix at the cause, not at each site. 20 of the 30 errors are one test double: a DatasourceStore
subclass that counts calls in get_count, set_count, get_all_count, has_key_count and
remove_key_count, none of which is declared on the class. Declaring them once clears all 20.
Where
tests/datasource/test_datasource_dict.py— 28 errors (21attr-definedfrom the test double above, 6explicit-override, 1 assignment).tests/datasource/data_connector/test_batch_filter.py— 1 error. The patterntests/datasource/data_connectorcovers seven modules; the other six already check clean.tests/datasource/fluent/tasks.py— 1 error.pyproject.toml— remove the threeexcludeentries namingtests/datasource/….scripts/mypy_relaxation_inventory.json— regenerate with the guard's emit mode, never by hand.
How to verify
pip install -r requirements-types.txt -r reqs/requirements-dev-contrib.txt
# remove the three tests/datasource/ lines from the exclude list in pyproject.toml, then:
python scripts/mypy_config_guard.py --emit-inventory > scripts/mypy_relaxation_inventory.json
invoke type-check --ci --pretty
pytest tests/datasource/test_datasource_dict.py tests/datasource/data_connector/Before: 30 errors in three files; 783 source files checked (at 2c4123fa9).
After: zero errors; 792 checked; those tests passing as they do today.
Requirements
- When the type-check runs on the merged change, it reports zero errors and none of the three
tests/datasource/…patterns remains. - The counter attributes must be declared on the test double itself, so one declaration clears every read of them — not annotated or cast at each of the 20 use sites.
- No test may be weakened: no assertion deleted or made vacuous, no expected value loosened,
no
Anyorcasthiding a real mismatch, no newskiporxfail. - The affected tests must pass with the same outcomes as before.
- The inventory must be regenerated by
python scripts/mypy_config_guard.py --emit-inventoryin the same change, and the guard must pass. - No file under
great_expectations/may change, and no test function signature may gain annotations. If the correct fix looks like it lies in library code, comment here instead.
Out of scope: every exclude pattern outside tests/datasource/; the
follow_imports = 'silent' override block; any mypy strictness flag; annotations on test
function signatures.
Notes
- The six
explicit-overrideerrors want the@overridedecorator, imported fromgreat_expectations.compatibility.typing_extensions— the shim this repo uses everywhere. tests/datasource/fluent/is otherwise already checked; onlytasks.pyinside it is excluded.
Source: fivetran/great_expectations