Skip to content

Conversation

@abates20
Copy link
Contributor

  • Resolves [Feature] Improved type hinting for DictList #1464
  • Improves type hinting for the DictList class by adding a TypeVar. This allows the specific type of object contained within an instantiated DictList to be defined. For example, the type for model.reactions is now DictList[Reaction] instead of just DictList. This means that now the hinted return type for model.reactions.get_by_id is Reaction instead of Object.
  • No tests added since only type hinting was changed.
  • add an entry to the next release



class DictList(list):
_TObject = TypeVar("_TObject", bound=Object)
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a more descriptive name. Also does it need to be a hidden object?

For instance

CobraObject = TypeVar("CobraObject", bound=Object)

looks clearer to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing it from _TObject to CobraObject sounds good to me. I went ahead and updated it.

@abates20 abates20 requested a review from cdiener December 3, 2025 14:38
@cdiener
Copy link
Member

cdiener commented Dec 4, 2025

Thank you!

@cdiener cdiener merged commit 5afa88d into opencobra:devel Dec 4, 2025
7 checks passed
@abates20 abates20 deleted the fix-improve-dictlist-type-hints branch December 4, 2025 14:31
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.

[Feature] Improved type hinting for DictList

2 participants