From 86224c760aca08e77e22b743cd4cef5f7042c37e Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 17 Dec 2022 10:49:22 -0700 Subject: [PATCH] Drop earlier Python compat --- urlman/__init__.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/urlman/__init__.py b/urlman/__init__.py index 9781753..89e2f1f 100644 --- a/urlman/__init__.py +++ b/urlman/__init__.py @@ -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 @@ -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. @@ -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] @@ -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"