Skip to content

TypeErrors against public interfaces. #122

Closed

Description

@lovelydinosaur

Partly prompted by this comment.

I think we should probably be a bit strict about enforcing types passed to our public interfaces. It'd be nice to raise loud clear errors, rather than failing with some arbitrary AttributeError in the middle of the codebase if a user passes something completely invalid to the interface. This would be stricter than what most Python libraries do, but I think it might be a good trade-off for us, to have a very strict and clearly demarked API.

That'd be easy enough to do since there's not too many points we'd need to enforce.
The big obvious one would be checking everything in AsyncClient.request(), which most of the rest of the public API calls into.

The would be some other bits & pieces to check too eg. Enforce that streaming data iterates through bytes/str, and not any other types. Enforce that dispatchers really do return a response type. Type checking on the various models that we expose.

Perhaps I'm being over-zelaous here? Any thoughts?

Activity

  1. sethmlarson commented on Jul 15, 2019

    @sethmlarson
    Contributor

    I'd rather be strict about what we accept, then we don't have to handle odd-ball cases down the road as a point of "backwards-compatibility" because it used to work but not on purpose.

  2. lovelydinosaur commented on Jul 15, 2019

    @lovelydinosaur
    MemberAuthor

    Sounds good to me.

  3. halbow commented on Jul 28, 2019

    @halbow
    Contributor

    I could take a look at this with ! :) I'll probably start with Client.request and AsynClient.request, do you have an idea/thoughts on the implementation ? (I was thinking that a decorator checking func.annotations could maybe do the trick)

  4. sethmlarson commented on Jul 28, 2019

    @sethmlarson
    Contributor

    Yeah start with a small example that Tom and I can take a look at for implementation review before we start applying it to all our interfaces. Are there any examples of this in another library?

  5. lovelydinosaur commented on Jul 29, 2019

    @lovelydinosaur
    MemberAuthor

    I was thinking that a decorator checking

    Indeed - I reckon a @typechecked decoartor approach is worth trying out here.
    We can keep it faily limited - it only needs to deal with the cases that we want to use it with.

    Wrt. implementation I'd suggest starting out by only handling checking of actual types, and treating any typing.Union/typing.Optional/typing.Dict cases all as Any.

    Once you've got it working with basic types you could then look at expanding it out to deal with the more complex composite cases.

  6. added this to the v1.0 milestone on Sep 15, 2019
  7. removed this from the v1.0 milestone on Dec 3, 2019
  8. lovelydinosaur commented on Dec 11, 2019

    @lovelydinosaur
    MemberAuthor

    We might want to have this at some point, but closing it as out-of-scope for now.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions