Verified Commit d2fa7200 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Don't confuse type checkers with register_pattern

parent d67c02be
Loading
Loading
Loading
Loading
+6 −2
Changes for behave_utils/url.py: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
#  Copyright 2021  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2021, 2026  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -15,14 +15,18 @@ from urllib.parse import urljoin
from .behave import register_pattern


@register_pattern(r"(?:https?://\S+|/\S*)")
class URL(str):
	"""
	A subclass for URL strings which also acts as a pattern match type
	"""

	__slots__ = ()

	def __truediv__(self, other: str) -> URL:
		return URL(urljoin(self, other))

	def __add__(self, other: str) -> URL:
		return URL(str(self) + other)


register_pattern(r"(?:https?://\S+|/\S*)", URL)