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

[3.10] __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= #82483

Closed
DeepSpace mannequin opened this issue Sep 27, 2019 · 10 comments
Closed
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@DeepSpace
Copy link
Mannequin

DeepSpace mannequin commented Sep 27, 2019

BPO 38302
Nosy @brettcannon, @serhiy-storchaka, @ammaraskar, @hongweipeng, @pablogsal
PRs
  • bpo-38302. __rpow__ now called when __ipow__ returns NotImplemented #16459
  • bpo-38302: when __ipow__ returns NotImplemented, fall back to __pow__/__rpow__ #24587
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-02-26.19:59:01.203>
    created_at = <Date 2019-09-27.21:55:15.670>
    labels = ['interpreter-core', 'type-bug', '3.10', 'release-blocker']
    title = '[3.10] __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **='
    updated_at = <Date 2021-02-26.19:59:01.202>
    user = 'https://bugs.python.org/DeepSpace'

    bugs.python.org fields:

    activity = <Date 2021-02-26.19:59:01.202>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-02-26.19:59:01.203>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2019-09-27.21:55:15.670>
    creator = 'DeepSpace'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38302
    keywords = ['patch']
    message_count = 10.0
    messages = ['353419', '353422', '353503', '353505', '353595', '375825', '376208', '386108', '386124', '387741']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'serhiy.storchaka', 'ammar2', 'hongweipeng', 'pablogsal', 'DeepSpace']
    pr_nums = ['16459', '24587']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38302'
    versions = ['Python 3.10']

    @DeepSpace
    Copy link
    Mannequin Author

    DeepSpace mannequin commented Sep 27, 2019

    Due to shared code between the 2 and 3 forms of pow, the following code causes a TypeError:

    class A:
        def __init__(self, val):
            self.val = val
        
        def __ipow__(self, other):
            return NotImplemented
    
    class B:
        def __init__(self, val):
            self.val = val
        
        def __rpow__(self, other):
            return A(other.val ** self.val)
    
    a = A(2)
    b = B(2)
    a **= b

    (https://stackoverflow.com/questions/58141475/ipow-raising-typeerror-when-left-hand-side-object-returns-notimplemented)

    @DeepSpace DeepSpace mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 27, 2019
    @DeepSpace
    Copy link
    Mannequin Author

    DeepSpace mannequin commented Sep 27, 2019

    Meant to say "... 2 and 3 arguments forms of pow, ..."

    @hongweipeng
    Copy link
    Mannequin

    hongweipeng mannequin commented Sep 29, 2019

    The document says(https://docs.python.org/3.9/reference/datamodel.html?highlight=__rpow__#object.\_\_rpow__):

    Note that ternary pow() will not try calling __rpow__() (the coercion rules would become too complicated).

    @ammaraskar
    Copy link
    Member

    This isn't the ternary form of pow(), the documentation there is referring to the pow(base, exp, modulus).

    @hongweipeng
    Copy link
    Mannequin

    hongweipeng mannequin commented Sep 30, 2019

    Oh, I see. Thank you.

    @brettcannon
    Copy link
    Member

    It turns out **= ONLY calls __ipow__ and neither __pow__ or __rpow__ as the data model says should be called.

    @brettcannon brettcannon added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes and removed 3.7 (EOL) end of life labels Aug 23, 2020
    @brettcannon brettcannon changed the title __rpow__ not reached when __ipow__ returns NotImplemented __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= Aug 23, 2020
    @brettcannon
    Copy link
    Member

    I have opened https://bugs.python.org/issue41688 to track the documentation fixes so that this can become a release blocker for Python 3.10.

    @brettcannon brettcannon added release-blocker and removed 3.8 only security fixes 3.9 only security fixes labels Sep 1, 2020
    @ambv ambv changed the title __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= [3.10] __pow__ and __rpow__ are not reached when __ipow__ returns NotImplemented for **= Oct 4, 2020
    @pablogsal
    Copy link
    Member

    Friendly reminder that this issue is currently blocking the 3.10a5 release. If you are ok with waiting for the next release to include the fix, please say so here or drop me an email/

    @brettcannon
    Copy link
    Member

    I'm totally fine with pushing this until b1 since this has been broken for ages.

    @brettcannon
    Copy link
    Member

    New changeset cc02b4f by Alex in branch 'master':
    bpo-38302: __pow__/rpow now called when __ipow__ returns NotImplemented (bpo-16459)
    cc02b4f

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants