Skip to content

Contextualize scheme registration API #28

Open
@markrwilliams

Description

@markrwilliams

hyperlink.register_scheme mutates global state. That's convenient but amounts to an import time side effect. If I do this in module a:

from hyperlink import register_scheme
register_scheme("blah")

I have to do this in module b:

from hyperlink import URL
import a

u = URL.from_text("blah://blah.com")

Scheme registration should be localized, returning a new URL-like object that knows about the registered schemes. That would let a look like this:

import hyperlink.URL as _URL

URL = _URL.schemes({"blah": "blah"})

So that b could do this:

from a import URL

u = URL.from_text({"blah": "blah"})

A context manager might be useful, too:

with URL.schemes({"blah": "blah"}) as blah_url:
    u = blah_url.from_text("blah://blah.com")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions