Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Jun 9, 2025

Summary

The tests were already in the right place, I just updated the documentation slightly to reflect the discussion here and on Discord.

Documentation: https://docs.astral.sh/ruff/rules/generic-not-last-base-class

Tests: https://github.com/astral-sh/ruff/blob/brent/release-0.12.0/crates/ruff_linter/src/rules/flake8_pyi/mod.rs#L51-L52

I considered mentioning the MRO explicitly and linking to this but decided that might be a bit too technical for the rule docs.

Now I see that ty links to the glossary, which would be another option.

Test Plan

Existing tests

Summary
--

The tests were already in the right place, I just updated the documentation
slightly to reflect the discussion
[here](#18519 (comment)) and
on Discord.

Documentation: https://docs.astral.sh/ruff/rules/generic-not-last-base-class

Tests: https://github.com/astral-sh/ruff/blob/brent/release-0.12.0/crates/ruff_linter/src/rules/flake8_pyi/mod.rs#L51-L52

Test Plan
--

Existing tests
@ntBre ntBre requested a review from AlexWaygood as a code owner June 9, 2025 22:41
@ntBre ntBre added the rule Implementing or modifying a lint rule label Jun 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+13 -0 violations, +0 -0 fixes in 5 projects; 50 projects unchanged)

apache/airflow (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ airflow-core/src/airflow/api_fastapi/auth/managers/base_auth_manager.py:78:22: PYI059 [*] `Generic[]` should always be the last base class
+ airflow-core/src/airflow/api_fastapi/common/exceptions.py:37:23: PYI059 [*] `Generic[]` should always be the last base class
+ airflow-core/src/airflow/api_fastapi/core_api/base.py:52:16: PYI059 [*] `Generic[]` should always be the last base class
+ airflow-core/src/airflow/api_fastapi/core_api/services/public/common.py:37:18: PYI059 [*] `Generic[]` should always be the last base class

langchain-ai/langchain (+4 -0 violations, +0 -0 fixes)

+ libs/core/langchain_core/output_parsers/base.py:31:26: PYI059 [*] `Generic[]` should always be the last base class
+ libs/core/langchain_core/prompts/base.py:45:25: PYI059 [*] `Generic[]` should always be the last base class
+ libs/core/langchain_core/runnables/base.py:111:15: PYI059 [*] `Generic[]` should always be the last base class
+ libs/core/langchain_core/stores.py:26:16: PYI059 [*] `Generic[]` should always be the last base class

latchbio/latch (+2 -0 violations, +0 -0 fixes)

+ src/latch/types/metadata.py:440:25: PYI059 [*] `Generic[]` should always be the last base class
+ src/latch/types/metadata.py:489:24: PYI059 [*] `Generic[]` should always be the last base class

python/typeshed (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select E,F,FA,I,PYI,RUF,UP,W

+ stdlib/asyncio/queues.pyi:28:12: PYI059 [*] `Generic[]` should always be the last base class

zulip/zulip (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ zerver/lib/notes.py:12:16: PYI059 [*] `Generic[]` should always be the last base class
+ zerver/lib/queue.py:35:18: PYI059 [*] `Generic[]` should always be the last base class

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI059 13 13 0 0 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
Copy link
Contributor Author

ntBre commented Jun 10, 2025

related: #18602

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 10, 2025

related: #18602

IMO I think that probably does block stabilisation, but I agree with you that for now we could just not offer a fix if there are any keyword or variadic arguments, stabilise it after making that change, and open a followup issue to add a fix for classes that have keyword arguments.

Variadic arguments (things like class Foo(*args): ... and class Bar(**args): ...) are rare enough in class definitions that I think it's fine for us never to offer a fix for those. But it would be nice to offer a fix for class Foo(Generic[T], Bar, metaclass=ABCMeta): ... at some point.

Comment on lines 16 to 17
/// The rule is also applied to stub files, where it won't cause issues at runtime,
/// because type checkers may also behave unpredictably in this case.
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd probably say something like "type checkers may not be able to infer an accurate MRO for for the class, which could lead to unexpected or inaccurate results when they analyze your code". Linking to the glossary sounds like a great idea!

Co-authored-by: Alex Waygood <[email protected]>
@ntBre
Copy link
Contributor Author

ntBre commented Jun 10, 2025

Closing this in light of the discussion on #18611 (need to move the fix to unsafe, updating the kwarg handling), but I'll copy the docs improvements over there.

@ntBre ntBre closed this Jun 10, 2025
@ntBre ntBre mentioned this pull request Jun 10, 2025
2 tasks
ntBre added a commit that referenced this pull request Jun 10, 2025
ntBre added a commit that referenced this pull request Sep 4, 2025
Tests and docs look good

We nearly stabilized this last
time (#18601) but it needed one more bug
fix and a documentation improvement (#18611)
ntBre added a commit that referenced this pull request Sep 4, 2025
Tests and docs look good

We nearly stabilized this last time
(#18601), but it needed one more
bug fix and a documentation improvement
(#18611)
ntBre added a commit that referenced this pull request Sep 8, 2025
Tests and docs look good

We nearly stabilized this last time
(#18601), but it needed one more
bug fix and a documentation improvement
(#18611)
ntBre added a commit that referenced this pull request Sep 10, 2025
Tests and docs look good

We nearly stabilized this last time
(#18601), but it needed one more
bug fix and a documentation improvement
(#18611)
ntBre added a commit that referenced this pull request Sep 10, 2025
Tests and docs look good

We nearly stabilized this last time
(#18601), but it needed one more
bug fix and a documentation improvement
(#18611)
ntBre added a commit that referenced this pull request Sep 10, 2025
Tests and docs look good

We nearly stabilized this last time
(#18601), but it needed one more
bug fix and a documentation improvement
(#18611)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants