Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
alexandrsatskov opened this issue May 18, 2023 · 3 comments · Fixed by #884
Closed
1 task done

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

alexandrsatskov opened this issue May 18, 2023 · 3 comments · Fixed by #884
Labels

Comments

@alexandrsatskov
Copy link

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:/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
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:/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
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
@xen
Copy link

xen commented May 25, 2023

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

@mjpieters
Copy link
Contributor

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.

@mjpieters
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants