0

I'd like to be able to differentiate between functions that return a URL vs a plain string (eg a local filepath vs a remote http URL)

Is there a way to do this with python type hints / PEP484?

def myfun() -> str:
    return "https://example.com/foo"
dcsan
  • 11,333
  • 15
  • 77
  • 118
  • 3
    This doesn't seem appropriate for type hints, unless you define a class for holding URLs instead of using strings. – Barmar Mar 23 '23 at 00:05
  • 1
    You could use `typing`'s `TypeVar` but that would only "trick" the type hinter, the actual type would still be `str`. Best case would be to describe a Class for Url's – TheLazyScripter Mar 23 '23 at 00:08

0 Answers0