-
Notifications
You must be signed in to change notification settings - Fork 23
fix: design and type hint of custom collections #2695
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2695 +/- ##
=======================================
Coverage 84.36% 84.36%
=======================================
Files 92 92
Lines 10890 10890
=======================================
Hits 9187 9187
Misses 1703 1703 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left some suggestions. Thanks for adding this, @moe-ad.
| from ansys.dpf.core.collection_base import CollectionBase | ||
| from ansys.dpf.core.common import create_dpf_instance | ||
|
|
||
| TYPE = TypeVar("TYPE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use T as per the original PEP 484:
| TYPE = TypeVar("TYPE") | |
| T = TypeVar("T") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer leaving this as is. Just to conform with the naming convention adopted for type parameters in other modules.
|
@moe-ad could we maybe add a comment about the presence of |
|
Some tests with 'continue-on-error: true' have failed:
Created by continue-on-error-comment |
Closes #2288.
The following changes have been made:
Collectionis also a generic type more explicit. From my investigation, this helps older type checker versions (especially on older python versions) infer types more accurately.CollectionFactoryfunction acollection_factoryclass method ofCollection. This is done for three main reasons:Collection.BaseClassargument. I couldn't think of a reason why a different argument other thanCollectionwill be passed. @PProfizi what do you think?Collectionis needed.With these changes, IDEs are now better able to suggest accurate autocompletion. Example in PyCharm:

The type inference is also much more accurate. For example, IDEs are able to infer that a

StringFieldsCollectioncontainsStringFields:And because of that, the type of the object returned by a call to

get_entrywill be inferred correctly asStringField:And only available methods of that object will be suggested through autocompletion:
