Skip to content

Commit

Permalink
Drop earlier Python compat
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Dec 17, 2022
1 parent 7291b8f commit 86224c7
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions urlman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@
__version__ = "2.0.1"


def with_metaclass(meta, *bases):
"""
Create a base class with a metaclass.
For Python 2.x and 3.x compatibility.
"""
# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(meta):
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)

return type.__new__(metaclass, "temporary_class", (), {})


class UrlsMetaclass(type):
"""
Metaclass which makes attribute access instantiate the class with
Expand All @@ -47,7 +31,7 @@ def __get__(self, instance, klass):
return self(klass, instance, self.__name__)


class Urls(with_metaclass(UrlsMetaclass)):
class Urls(metaclass=UrlsMetaclass):
"""
Special object which lets you specify URL strings for objects.
Expand All @@ -65,7 +49,7 @@ def __init__(self, klass, instance, name):
def __getattr__(self, attr):
return self.get_url(attr)

def get_url(self, attr):
def get_url(self, attr: str) -> "UrlString":
# Get the URL value
try:
url = self.urls[attr]
Expand Down Expand Up @@ -93,10 +77,10 @@ def get_example_url(self, attr):
value = UrlFormatter(self, example=True).vformat(url, [], {})
return value

def get_scheme(self, url):
def get_scheme(self, url: "UrlString"):
return "http"

def get_hostname(self, url):
def get_hostname(self, url: "UrlString"):
return "localhost"


Expand Down

0 comments on commit 86224c7

Please sign in to comment.