Skip to content

[fix] AttributeError crash when a slice is used as a class decorator #10350

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas commented Apr 23, 2025

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

This was partially implemented by an AI bot (codegen-bot), credited as co-author in the commit. I've done some chores (moving functional tests, fixing the new test, creating the changelog, checking that the changes are actually required and that the not required changes are not actually another crash), and some I did not (creating branches, it could have opened the PR if I wasn't working on a fork, creating the regression tests, making the initial fix). Tried to kept the history truthful to what happened. Overall not sure if it's more work or less work than just copy pasting the regression code and fixing myself (probably more), but it certainly feel new and exciting.

Suggestions on what to try next with this AI bot are welcome, I started with "noqa" handling but it seems a little too complicated. I probably should use this on task with less finesse and more grunt work, like refactor (?)

Closes #10334

@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.7 milestone Apr 23, 2025
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the codegen-bot/fix-slice-decorator-crash branch from 68b72f9 to 49baeb3 Compare April 23, 2025 06:44
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the codegen-bot/fix-slice-decorator-crash branch from 1e5e8c1 to d3c29cc Compare April 23, 2025 07:01
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the codegen-bot/fix-slice-decorator-crash branch from d3c29cc to 754cfcb Compare April 23, 2025 07:03
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.90%. Comparing base (8a733fc) to head (8be5e62).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10350   +/-   ##
=======================================
  Coverage   95.90%   95.90%           
=======================================
  Files         176      176           
  Lines       19122    19122           
=======================================
  Hits        18339    18339           
  Misses        783      783           
Files with missing lines Coverage Ξ”
pylint/checkers/deprecated.py 99.06% <100.00%> (ΓΈ)
pylint/checkers/utils.py 95.92% <ΓΈ> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes an AttributeError crash that occurred when a slice object was used as a class decorator. The changes include the addition of regression tests to reproduce the issue and adjustments in the Pylint checkers to prevent incorrect attribute access during inference.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
tests/functional/r/regression_02/regression_10334.txt Adds expected test output indicating non-callable error.
tests/functional/r/regression_02/regression_10334.py Provides a test case using a slice as a decorator.
pylint/checkers/utils.py Updates attribute checks to safely verify presence of qname.
pylint/checkers/deprecated.py Adds a qname attribute check to avoid AttributeError.
Files not reviewed (1)
  • doc/whatsnew/fragments/10334.bugfix: Language not supported

Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on django:
The following messages are no longer emitted:

  1. invalid-name:
    Attribute name "ALLOWED_HOSTS" doesn't conform to snake_case naming style
    https://github.com/django/django/blob/1831f7733d3ef03d1ca7fac3e8d9f4c5e3e3375e/django/test/utils.py#L141
  2. invalid-name:
    Attribute name "DEBUG" doesn't conform to snake_case naming style
    https://github.com/django/django/blob/1831f7733d3ef03d1ca7fac3e8d9f4c5e3e3375e/django/test/utils.py#L144
  3. invalid-name:
    Attribute name "EMAIL_BACKEND" doesn't conform to snake_case naming style
    https://github.com/django/django/blob/1831f7733d3ef03d1ca7fac3e8d9f4c5e3e3375e/django/test/utils.py#L147
  4. invalid-name:
    Attribute name "MIGRATION_MODULES" doesn't conform to snake_case naming style
    https://github.com/django/django/blob/1831f7733d3ef03d1ca7fac3e8d9f4c5e3e3375e/django/db/backends/base/creation.py#L79

Effect on pandas:
The following messages are now emitted:

  1. attribute-defined-outside-init:
    Attribute 'name' defined outside init
    https://github.com/pandas-dev/pandas/blob/e5898b8d33ac943a60250e1466006c073a506e8c/pandas/core/frame.py#L10693

This comment was generated for commit 8be5e62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'Slice' object has no attribute 'name' when a slice is used as a class decorator
1 participant