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

Please consider mentioning property without setter when an attribute can't be set #90886

Closed
NeilGirdhar mannequin opened this issue Feb 12, 2022 · 9 comments
Closed

Please consider mentioning property without setter when an attribute can't be set #90886

NeilGirdhar mannequin opened this issue Feb 12, 2022 · 9 comments
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@NeilGirdhar
Copy link
Mannequin

NeilGirdhar mannequin commented Feb 12, 2022

BPO 46730
Nosy @rhettinger, @tiran, @NeilGirdhar, @tirkarthi, @sweeneyde, @Alex-Blade
PRs
  • bpo-46730: Add more info to @property AttributeError messages #31311
  • bpo-46730: Fix refleak and tighten NULL checks #31389
  • bpo-46730: Use raw string to avoid deprecation warning #31427
  • 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 2022-02-16.07:16:46.216>
    created_at = <Date 2022-02-12.11:15:48.674>
    labels = ['interpreter-core', '3.11']
    title = "Please consider mentioning property without setter when an attribute can't be set"
    updated_at = <Date 2022-02-19.05:36:47.897>
    user = 'https://github.com/NeilGirdhar'

    bugs.python.org fields:

    activity = <Date 2022-02-19.05:36:47.897>
    actor = 'Dennis Sweeney'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-16.07:16:46.216>
    closer = 'Dennis Sweeney'
    components = ['Interpreter Core']
    creation = <Date 2022-02-12.11:15:48.674>
    creator = 'NeilGirdhar'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46730
    keywords = ['patch']
    message_count = 9.0
    messages = ['413122', '413152', '413153', '413154', '413161', '413318', '413319', '413446', '413532']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'christian.heimes', 'NeilGirdhar', 'xtreak', 'Dennis Sweeney', 'Alex-Blade']
    pr_nums = ['31311', '31389', '31427']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46730'
    versions = ['Python 3.11']

    @NeilGirdhar
    Copy link
    Mannequin Author

    NeilGirdhar mannequin commented Feb 12, 2022

    class C:
        @property
        def f(self) -> int:
            return 2
    
    class D(C):
        pass

    D().f = 2

    Gives:

    Traceback (most recent call last):
      File "/home/neil/src/cmm/a.py", line 10, in <module>
        D().f = 2
    AttributeError: can't set attribute 'f'

    This can be a pain to debug when the property is buried in a base class. Would it make sense to mention the reason why the attribute can't be set, namely that it's on a property without a setter?

    @NeilGirdhar NeilGirdhar mannequin added 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 12, 2022
    @Alex-Blade
    Copy link
    Mannequin

    Alex-Blade mannequin commented Feb 13, 2022

    Indeed, the error message does not help to identify the problem. Moreover, it collides with similar errors in namedtuple and DynamicClassAttribute which may lead to even more confusion.

    I made a draft patch that could help with it (Alex-Blade@06df3a7), but I have a concern related to backwards compatibility (that's why no PR). I don't really understand if according to PEP-387 a change in an exception message should be considered compatibility breaking?

    @NeilGirdhar
    Copy link
    Mannequin Author

    NeilGirdhar mannequin commented Feb 13, 2022

    Thank you, this would have saved me a lot of time!

    On Sat, Feb 12, 2022 at 8:37 PM Alexander <report@bugs.python.org> wrote:

    Alexander <lakeevveekal@gmail.com> added the comment:

    Indeed, the error message does not help to identify the problem. Moreover,
    it collides with similar errors in namedtuple and DynamicClassAttribute
    which may lead to even more confusion.

    I made a draft patch that could help with it (
    Alex-Blade@06df3a7),
    but I have a concern related to backwards compatibility (that's why no PR).
    I don't really understand if according to PEP-387 a change in an exception
    message should be considered compatibility breaking?

    ----------
    nosy: +Alex-Blade


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue46730\>


    @sweeneyde
    Copy link
    Member

    Go ahead and open a PR -- it makes it easier to discuss particular changes.

    Regarding backwards-compatibility, error messages improvements are fair game for Python 3.11, we just shouldn't backport them to earlier versions.

    We can also consider including the type of the relevant object in the error messages.

    @Alex-Blade
    Copy link
    Mannequin

    Alex-Blade mannequin commented Feb 13, 2022

    Added the PR. (I have signed the CLA, just haven't got the response yet, doesn't affect the discussion I guess)

    @sweeneyde
    Copy link
    Member

    New changeset 0cb765b by Alex-Blade in branch 'main':
    bpo-46730: Add more info to @Property AttributeError messages (GH-31311)
    0cb765b

    @sweeneyde
    Copy link
    Member

    Thanks for the PR!

    @sweeneyde
    Copy link
    Member

    New changeset 9e06d03 by Christian Heimes in branch 'main':
    bpo-46730: Fix refleak and tighten NULL checks (GH-31389)
    9e06d03

    @tirkarthi
    Copy link
    Member

    The test introduces a deprecation warning. It might be fixed by using raw string like the msg_format used in other test.

    ./python -Wall -m py_compile Lib/test/test_property.py
    Lib/test/test_property.py:345: DeprecationWarning: invalid escape sequence '\.'
    msg_format = "^property of 'PropertyUnreachableAttributeNoName\.cls' object {}$"

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants