Skip to content

Type-checking our tests #650

Closed
Closed

Description

@florimondmanca

I know this is not a standard thing to do across Encode projects, but I've been wondering if it would be worth starting to type-hint our tests.

I've seen at least two instances of this recently:

My rationale is based on two aspects:

  • It improves our upfront knowledge about how users will actually use HTTPX — currently their usage of type hints in the wild is not reflected anywhere.
  • It helps us catch type hint inconsistencies we wouldn't see in the core package.

The main counter-argument, I suppose, is that type hinting tests is tedious. I think that's fair, but I believe the two pro's above make it compelling.

Thoughts?

Activity

  1. florimondmanca commented on Dec 19, 2019

    @florimondmanca
    ContributorAuthor

    Alternatively, we could tweak the mypy config:

    [mypy]
    files = httpx, tests
    ignore_missing_imports = True
    disallow_untyped_defs = False
    check_untyped_defs = True
    
    [mypy-httpx]
    disallow_untyped_defs = True
    check_untyped_defs = False

    Running this locally raises 141 errors, but mostly on internal APIs, so, hmm.

  2. aalvrz commented on Dec 23, 2019

    @aalvrz
    Contributor

    I think this is a great idea, would like to work on this. Since I am pretty new to httpx, adding these type hints to the tests will give me a better picture of how httpx works under the hood.

  3. florimondmanca commented on Mar 13, 2020

    @florimondmanca
    ContributorAuthor

    I think this is still a good idea, though it's a bit of busy work to upgrade our existing test code.

    Let's perhaps just remind ourselves to add types whenever we add/touch existing tests?

  4. Pradhvan commented on Jun 17, 2020

    @Pradhvan

    @florimondmanca I see a lot of merged PR. I guess you should close this ? 😄

  5. florimondmanca commented on Jun 17, 2020

    @florimondmanca
    ContributorAuthor

    I think there’s one small last step which would be to add tests/ to the mypy arguments in the check script. :-) Once this is enforced then yup, we can close this off.

  6. Pradhvan commented on Jun 18, 2020

    @Pradhvan

    I am currently working on a different Good First Issue PR and when that is done. I would be happy to pick up what's remaining in this PR so we can close this one too. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedExtra attention is neededtoolingChanges to our CI/CD, tests setup, etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions