Skip to content

Support generic parents in include_subclasses strategy #650

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

Conversation

zhukovgreen
Copy link
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
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
Copy link
Member

@Tinche Tinche left a comment

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
Copy link
Member

Tinche commented May 26, 2025

Thanks!

@Tinche Tinche merged commit ea4c311 into python-attrs:main May 26, 2025
11 checks passed
@zhukovgreen
Copy link
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