Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better error message for assignment to non-existent __slots__ #96663

Closed
Labels
type-featureA feature request or enhancement
@Gobot1234

Description

@Gobot1234

Feature or enhancement

Currently, the error message for an attribute that isn't included in a class's__slots__ is harder to understand than I think it needs to be.

Python 3.12.0a0 (heads/main:4114bcc, Sep  7 2022, 19:35:54) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwinType "help", "copyright", "credits" or "license" for more information.>>>classFoo:...__slots__= ("bar",)... >>> Foo().not_an_attribute=1234Traceback (most recent call last):  File "<stdin>", line 1, in <module>AttributeError: 'Foo' object has no attribute 'not_an_attribute'

Pitch

I think the message can be improved in multiple ways and be made more similar to the error message for attribute access:

  1. Make the error message contain a note as to why the assignment failed. Ideally, this would look something like
    AttributeError:'Foo'cannothaveattribute'not_an_attribute'setasitisnotincludedinits__slots__
  2. Make the error message more forgiving in the case of a typo.
    >>> Foo().bat="hello world"Traceback (most recent call last):  File "<stdin>", line 1, in <module>AttributeError: 'Foo' cannot have attribute 'bat' set as it is not included in its __slots__. Did you mean: 'bar'?
  3. Support more introspection on the raised AttributeError as currently name and obj are None.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp