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

Allow update __class__ for mutable types or module subclasses #5225

Merged
merged 3 commits into from
Apr 14, 2024

Conversation

moreal
Copy link
Contributor

@moreal moreal commented Apr 12, 2024

Description

This pull request is related with #5105. The error was raised when executing the below lines:

if not six.PY2:

    class RequestModule(sys.modules[__name__].__class__):
        def __call__(self, *args, **kwargs):
            """
            If user tries to call this module directly urllib3 v2.x style raise an error to the user
            suggesting they may need urllib3 v2
            """
            raise TypeError(
                "'module' object is not callable\n"
                "urllib3.request() method is not supported in this release, "
                "upgrade to urllib3 v2 to use it\n"
                "see https://urllib3.readthedocs.io/en/stable/v2-migration-guide.html"
            )

    sys.modules[__name__].__class__ = RequestModule  # HERE.

I thought it is because RustPython doesn't allow update even if the value is module's subclass. This pull request just updates it.

CPython implementation

@moreal moreal force-pushed the obj-set-class branch 3 times, most recently from e17f303 to 802e045 Compare April 13, 2024 05:46
@moreal moreal changed the title Allow update __class__ for module subclasses Allow update __class__ for mutable types or module subclasses Apr 14, 2024
@moreal moreal marked this pull request as ready for review April 14, 2024 03:22
Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and welcome back!

@youknowone youknowone merged commit 4d5cf24 into RustPython:main Apr 14, 2024
11 checks passed
This was referenced Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants