-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
2a06afd
to
cb0814c
Compare
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 |
…uto casting" 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 is ok.
Co-authored-by: Chris Markiewicz <[email protected]>
Co-authored-by: Chris Markiewicz <[email protected]>
for more information, see https://pre-commit.ci
@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 |
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.
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.
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 |
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.
Another re-ordering of branching.
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 |
Types of changes
Summary
Checklist