Skip to content

Support generic parents in include_subclasses strategy - #650

Merged
Tinche merged 1 commit into
python-attrs:mainfrom
zhukovgreen:fix/648/support-generics-in-include-subclasses-strategy
May 26, 2025
Merged

Tinche merged 1 commit into
python-attrs:mainfrom
zhukovgreen:fix/648/support-generics-in-include-subclasses-strategy

Conversation

@zhukovgreen

Copy link
Copy Markdown
Contributor

Resolves #648

The strategy was using parent_cls.subclasses() to get the list of subclasses. In case of generics, this method is unavailable.

The fix applies sanitizing the cl and getting its origin class for getting a sublcasses tree.

The class itself remains generic in the tree.

@zhukovgreen

Copy link
Copy Markdown
Contributor Author

@Tinche sorry for bombing you: ) just would like to get rid form my custom implementation in one of our project. If you have time today - highly appreciated

@Tinche
Tinche self-requested a review May 25, 2025 10:57

@Tinche Tinche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Left a small comment, and let's add a CHANGELOG entry (I suggest somewhere in the middle, after new features but above boring infrastructure stuff).

Resolves python-attrs#648

The strategy was using parent_cls.__subclasses__() to get the
list of subclasses. In case of generics, this method
is unavailable.

The fix applies sanitizing the cl and getting its origin
class for getting the sublcasses tree.

The class itself remains generic in the tree.
@zhukovgreen
zhukovgreen force-pushed the fix/648/support-generics-in-include-subclasses-strategy branch from 25a31ca to d68583a Compare May 26, 2025 12:56
@zhukovgreen
zhukovgreen requested a review from Tinche May 26, 2025 12:57
@Tinche

Tinche commented May 26, 2025

Copy link
Copy Markdown
Member

Thanks!

@Tinche
Tinche merged commit ea4c311 into python-attrs:main May 26, 2025
@zhukovgreen

Copy link
Copy Markdown
Contributor Author

Thanks for a cool library!

@zhukovgreen
zhukovgreen deleted the fix/648/support-generics-in-include-subclasses-strategy branch May 26, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

include_subclasses fails for classes with generics. AttributeError: __subclasses__. Did you mean: '__subclasscheck__'?

2 participants