Skip to content

Fixed typing in 'import_classes_from_module' function - #48

Merged
ab295382 merged 2 commits into
mainfrom
bugfix/typing-fix
Aug 18, 2026
Merged

Fixed typing in 'import_classes_from_module' function#48
ab295382 merged 2 commits into
mainfrom
bugfix/typing-fix

Conversation

@gchqdev227

@gchqdev227 gchqdev227 commented Aug 17, 2026

Copy link
Copy Markdown
Member

This PR fixes a typing error that occurs in the import_classes_from_module function on newer versions of mypy:

concoursetools/importing.py:73: error: Incompatible return value type (got "dict[str, type[object]]", expected "dict[str, type[T]]")  [return-value]

For some reason, issubclass was not type narrowing. I've rewritten the code slightly to drop a conditional in favour of an earlier continue statement. This also avoids a tiny bit of work for other classes.

In additional, I dropped a try/except block for a TypeError raised by issubclass. I assume this exists because issubclass will raise TypeError if not passed a class, but given we're running inspect.isclass as a predicate above, I assume the only issue we could have here would be due to some particularly heinous metaprogramming, so I think it's fine!

This has now been reverted, as it turns out the issue was due to Python 3.10.

@gchqdev227 gchqdev227 self-assigned this Aug 17, 2026
@ab295382
ab295382 merged commit e670753 into main Aug 18, 2026
10 checks passed
@ab295382
ab295382 deleted the bugfix/typing-fix branch August 18, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants