aio-libs / yarl

Yet another URL library

Home Page:https://yarl.aio-libs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError on URL join with enum.StrEnum classes for yarl==1.9.1+

alexandrsatskov opened this issue · comments

Describe the bug

Joining a path with StrEnum class raise TypeError for yarl==1.9.1+ (for example yarl==1.8.2 works fine)

To Reproduce

from enum import StrEnum

from yarl import URL


class Endpoints(StrEnum):
    GET_USERS = "building/users"
    CREATE_USER = "building/users/create"


if __name__ == "__main__":
    url = URL("https://example.com") / Endpoints.GET_USERS
    print(url)

    # yarl==1.8.2 result:
    # https://example.com/building/users

    # yarl==1.9.1+ result:
    # Traceback (most recent call last):
    #   File "<FILE_PATH>", line 15, in <module>
    #     url = URL("https://example.com") / Endpoints.GET_USERS
    #           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
    # TypeError: unsupported operand type(s) for /: 'URL' and 'Endpoints'``

Expected behavior

The same begavior as for previous versions (yarl==1.8.2 for example)

Logs/tracebacks

Traceback (most recent call last):
  File "/home/satskov/PycharmProjects/alice/tmp.py", line 15, in <module>
    url = URL("https://example.com") / Endpoints.GET_USERS
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'URL' and 'Endpoints'

Python Version

$ python --version
Python 3.11.0

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/satskov/PycharmProjects/alice/venv/lib/python3.11/site-packages
Requires: 
Required-by: aiohttp, core, yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.9.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /home/satskov/PycharmProjects/alice/venv/lib/python3.11/site-packages
Requires: idna, multidict
Required-by: aiohttp, core

OS

Linux Mint 20.1 (Ulyssa)
Linux 5.4.0-128-generic #144-Ubuntu SMP Tue Sep 20 11:00:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Use url = URL("https://example.com") / Endpoints.GET_USERS.value

Use url = URL("https://example.com") / Endpoints.GET_USERS.value

Yet, that's missing the point. I do think that accepting StrEnum values should work here.

This was introduced by #831, but the type check is too narrow.