Skip to content

API design question - Response.url #113

Closed

Description

@lovelydinosaur

Currently our Response.url attribute exposes a URL instance.

This is a breaking change from the requests API where it just exposes a plain string.

It's feasible that we should instead only be exposing plain string URLs, in order to aim for drop-in replacement API compatibility w/ requests, and in order to keep the API surface area low.

Options here are:

  • Expose request.url as a URL instance. (Richer information, URL class is also useful in its own right.)
  • Expose request.url as a str. (Better API compat. Lower API surface area to maintain.)
  • Expose request.url as a str, and request.urlinfo as a URL instance. (Better API compat. High API surface area.)

Activity

  1. lovelydinosaur commented on Jul 9, 2019

    @lovelydinosaur
    MemberAuthor

    If we do keep it as a URL instance, then one option to keep closer API compat would be to allow string comparisons, eg URL(“https://www.encode.io/“) == “https://www.encode.io/“

    That has the advantage of being string-like, and far less likely to introduce any API breakage.

  2. sethmlarson commented on Jul 9, 2019

    @sethmlarson
    Contributor

    I'm for allowing string comparisons and providing the read-only URL instance. :) Seems like something users are probably doing themselves and shouldn't have to.

  3. lovelydinosaur commented on Jul 9, 2019

    @lovelydinosaur
    MemberAuthor

    Seems like it's probably the best all round option yeah.

  4. graingert commented on Jul 10, 2019

    @graingert
    Contributor

    how about:

    with http3.Session(requests_compat=True) as s:
        assert type(s.get("https://example.com").url) is str
    
  5. sethmlarson commented on Jul 10, 2019

    @sethmlarson
    Contributor

    I'd say that flags / parameters that massively alter the behavior of a function should probably be avoided.
    Typically what a lot of URL instance classes do to recover the original string for the URL is provide an .unsplit() method.

  6. graingert commented on Jul 11, 2019

    @graingert
    Contributor

    How about instead of maintaining backwards compatibility with requests, provide a series of codemods so people can upgrade their code to the new api?

  7. sethmlarson commented on Jul 11, 2019

    @sethmlarson
    Contributor

    We'll definitely need a section in the documentation on migration strategy, especially from requests but also useful to how for instance urllib3 does something compared to http3.

  8. StephenBrown2 commented on Jul 14, 2019

    @StephenBrown2
    Contributor

    Personally I am quite in favor of the URL class, and am currently using urlpath for approximately the same function, including the ability to concatenate parts with /. Making URL instances string comparable (and bonus: / concat-able!) would be the best option I think, giving the best of both worlds.

  9. added this to the v1.0 milestone on Sep 15, 2019
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions