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

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

DeepSpace mannequin opened this issue Sep 27, 2019 · 10 comments
Labels
3.10 interpreter-core release-blocker type-bug

Comments

@DeepSpace
Copy link
Mannequin

@DeepSpace DeepSpace mannequin commented Sep 27, 2019

BPO 38302
Nosy @brettcannon, @serhiy-storchaka, @ammaraskar, @hongweipeng, @pablogsal
PRs
  • #16459
  • #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 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 interpreter-core type-bug labels Sep 27, 2019
    @DeepSpace
    Copy link
    Mannequin Author

    @DeepSpace DeepSpace mannequin commented Sep 27, 2019

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

    @hongweipeng
    Copy link
    Mannequin

    @hongweipeng 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

    @ammaraskar ammaraskar commented Sep 29, 2019

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

    @hongweipeng
    Copy link
    Mannequin

    @hongweipeng hongweipeng mannequin commented Sep 30, 2019

    Oh, I see. Thank you.

    @brettcannon
    Copy link
    Member

    @brettcannon brettcannon commented Aug 23, 2020

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

    @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

    @brettcannon brettcannon commented Sep 1, 2020

    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.

    @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

    @pablogsal pablogsal commented Feb 1, 2021

    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

    @brettcannon brettcannon commented Feb 2, 2021

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

    @brettcannon
    Copy link
    Member

    @brettcannon brettcannon commented Feb 26, 2021

    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 interpreter-core release-blocker type-bug
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants