Skip to content
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

fixes issues with super->sub-class auto-cast and handles MultiInputObj coercion #746

Merged
merged 9 commits into from
Jun 3, 2024

Conversation

tclose
Copy link
Contributor

@tclose tclose commented Apr 5, 2024

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Summary

  • fixes bugs with super->sub-class auto-casting, including when the sub-classes are part of a union. If the super class is a super class of any of the union args then it passes the check.
  • adds handling for MultiInputObj
  • streamlines typing error messages

Checklist

  • I have added tests to cover my changes (if necessary)

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 97.76536% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 88.01%. Comparing base (7d84fba) to head (4c00389).
Report is 9 commits behind head on master.

Current head 4c00389 differs from pull request most recent head ad28ae5

Please upload reports for the commit ad28ae5 to get more accurate results.

Files Patch % Lines
pydra/utils/typing.py 93.44% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #746       +/-   ##
===========================================
+ Coverage   15.14%   88.01%   +72.87%     
===========================================
  Files          53       53               
  Lines       15693    15817      +124     
  Branches     2788     1610     -1178     
===========================================
+ Hits         2376    13922    +11546     
+ Misses      12988     1893    -11095     
+ Partials      329        2      -327     
Flag Coverage Δ
unittests 88.01% <97.76%> (+72.91%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tclose tclose force-pushed the typing-bugfixes branch 3 times, most recently from 2a06afd to cb0814c Compare May 21, 2024 21:45
@tclose tclose requested a review from djarecka May 21, 2024 21:56
@tclose tclose added bug Something isn't working patch Increment the patch version when merged (label from auto) release Triggers publishing with auto labels May 21, 2024
@tclose
Copy link
Contributor Author

tclose commented May 22, 2024

NB: the reference hash updates required in the unittests seem be related to changes to the file-hashing process. This could be due to a change in fileformats but I can't remember making any changes that would be related.

pydra/utils/tests/test_typing.py Show resolved Hide resolved
pydra/utils/tests/test_typing.py Show resolved Hide resolved
pydra/utils/tests/test_typing.py Outdated Show resolved Hide resolved
pydra/utils/typing.py Outdated Show resolved Hide resolved
@tclose
Copy link
Contributor Author

tclose commented May 30, 2024

@effigies I have parametrized a number of test batches, there a couple more that could probably be done but would require a bit more work so I thought I could leave them for now.

@djarecka if you are busy are you happy to merge if @effigies has been through it? It just cleans up some corner cases that were missed in the original PR

Copy link
Contributor

@effigies effigies left a comment

Choose a reason for hiding this comment

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

It looks like coerce() and check_type() have a lot of duplicated code. Does not need to be addressed now, but this is inviting desynchronization and fixing bugs in one and not the other.

Otherwise LGTM.

Comment on lines +373 to +390
except TypeError as e:
# Special handling for MultiInputObjects (which are annoying)
if isinstance(self.pattern, tuple) and self.pattern[0] == MultiInputObj:
# Attempt to coerce the object into arg type of the MultiInputObj first,
# and if that fails, try to coerce it into a list of the arg type
inner_type_parser = copy(self)
inner_type_parser.pattern = self.pattern[1][0]
try:
return [inner_type_parser.coerce(object_)]
except TypeError:
add_exc_note(
e,
"Also failed to coerce to the arg-type of the MultiInputObj "
f"({self.pattern[1][0]})",
)
raise e
else:
raise e
Copy link
Contributor

Choose a reason for hiding this comment

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

Another re-ordering of branching.

Suggested change
except TypeError as e:
# Special handling for MultiInputObjects (which are annoying)
if isinstance(self.pattern, tuple) and self.pattern[0] == MultiInputObj:
# Attempt to coerce the object into arg type of the MultiInputObj first,
# and if that fails, try to coerce it into a list of the arg type
inner_type_parser = copy(self)
inner_type_parser.pattern = self.pattern[1][0]
try:
return [inner_type_parser.coerce(object_)]
except TypeError:
add_exc_note(
e,
"Also failed to coerce to the arg-type of the MultiInputObj "
f"({self.pattern[1][0]})",
)
raise e
else:
raise e
except TypeError as e:
# Special handling for MultiInputObjects (which are annoying)
if not isinstance(self.pattern, tuple) or self.pattern[0] != MultiInputObj:
raise e
# Attempt to coerce the object into arg type of the MultiInputObj first,
# and if that fails, try to coerce it into a list of the arg type
inner_type_parser = copy(self)
inner_type_parser.pattern = self.pattern[1][0]
try:
return [inner_type_parser.coerce(object_)]
except TypeError:
add_exc_note(
e,
"Also failed to coerce to the arg-type of the MultiInputObj "
f"({self.pattern[1][0]})",
)
raise e

@tclose tclose merged commit d674840 into master Jun 3, 2024
41 checks passed
@tclose tclose deleted the typing-bugfixes branch June 3, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch Increment the patch version when merged (label from auto) release Triggers publishing with auto
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants