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

Added handling of hashing of types with args and typing special forms #684

Merged
merged 11 commits into from
Sep 8, 2023

Conversation

tclose
Copy link
Contributor

@tclose tclose commented Aug 4, 2023

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

Summary

Handles the case of hashing a class with type args, typing special forms (e.g. Union, ty.Type) and classes that inherit from ty.Generic

Checklist

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

@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +4.28% 🎉

Comparison is base (103cefc) 78.71% compared to head (fa7887b) 82.99%.
Report is 3 commits behind head on master.

❗ Current head fa7887b differs from pull request most recent head 4809dfe. Consider uploading reports for the commit 4809dfe to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   78.71%   82.99%   +4.28%     
==========================================
  Files          22       22              
  Lines        4873     4894      +21     
  Branches     1401        0    -1401     
==========================================
+ Hits         3836     4062     +226     
- Misses        831      832       +1     
+ Partials      206        0     -206     
Flag Coverage Δ
unittests 82.99% <100.00%> (+4.42%) ⬆️

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

Files Changed Coverage Δ
pydra/utils/hash.py 95.03% <100.00%> (+2.88%) ⬆️

... and 16 files with indirect coverage changes

☔ View full report in Codecov by Sentry.

📢 Have feedback on the report? Share it here.

pydra/utils/hash.py Outdated Show resolved Hide resolved
@tclose tclose changed the title added handling of hashing of types with args and typing special forms WIP: Added handling of hashing of types with args and typing special forms Aug 6, 2023
@tclose tclose changed the title WIP: Added handling of hashing of types with args and typing special forms Added handling of hashing of types with args and typing special forms Sep 6, 2023
@tclose
Copy link
Contributor Author

tclose commented Sep 6, 2023

@djarecka this PR is ready to merge now. I'm not sure where the coverage misses are coming from as it is primarily to do with the Dask worker (18 lines). Note that this PR is rebased off #687, so that should be merged first

@effigies effigies mentioned this pull request Sep 7, 2023
2 tasks
@effigies effigies closed this Sep 7, 2023
@effigies effigies reopened this Sep 7, 2023
@effigies
Copy link
Contributor

effigies commented Sep 7, 2023

@djarecka SLURM passed here. It might be worth digging into the runner setup info to see if some details of the machine this is run on differ between successes and crashes/timeouts.

e.g.,

image

pydra/utils/hash.py Outdated Show resolved Hide resolved
pydra/utils/hash.py Outdated Show resolved Hide resolved
pydra/utils/hash.py Show resolved Hide resolved
pydra/utils/tests/test_hash.py Outdated Show resolved Hide resolved
pydra/utils/tests/test_hash.py Outdated Show resolved Hide resolved
pydra/utils/hash.py Outdated Show resolved Hide resolved
pydra/utils/tests/test_hash.py Outdated Show resolved Hide resolved
tclose and others added 6 commits September 8, 2023 08:46
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
@effigies
Copy link
Contributor

effigies commented Sep 8, 2023

What happens if someone uses from __future__ import annotations in their module?

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

What happens if someone uses from __future__ import annotations in their module?

That's a good question. I strongly suspect it would break things. However, we should be able to detect them and evaluate the class strings to proper classes when we create interfaces.

Happy to look into this if we end up refactoring the task/interface syntax

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

What happens if someone uses from __future__ import annotations in their module?

That's a good question. I strongly suspect it would break things. However, we should be able to detect them and evaluate the class strings to proper classes when we create interfaces.

Happy to look into this if we end up refactoring the task/interface syntax

Actually, looking at the code I think that attrs probably handles this for us

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

What happens if someone uses from __future__ import annotations in their module?

That's a good question. I strongly suspect it would break things. However, we should be able to detect them and evaluate the class strings to proper classes when we create interfaces.
Happy to look into this if we end up refactoring the task/interface syntax

Actually, looking at the code I think that attrs probably handles this for us

Just checked with the following, and attrs doesn't help us

from __future__ import annotations
import attrs


@attrs.define
class A:
    x: int = 0
    y: float = 1.0


print(repr(attrs.fields(A).x.type))

@effigies
Copy link
Contributor

effigies commented Sep 8, 2023

Okay. I think it's fair to call that a limitation but not agonize over it. It might cause some cache misses based on changes in Python version or the package that defines a task, but we should be consistent across runs of the same code on the same Python version.

Under what circumstances are we actually hashing types? We're hashing values, so it seems like this should be moot for most cases.

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

Okay. I think it's fair to call that a limitation but not agonize over it. It might cause some cache misses based on changes in Python version or the package that defines a task, but we should be consistent across runs of the same code on the same Python version.

Under what circumstances are we actually hashing types? We're hashing values, so it seems like this should be moot for most cases.

As I mentioned, I expect it to be pretty specific to my code, but in Arcana, the file-format class that input data files are stored in and output data files should be stored in is passed as an input to the "source" and "sink" nodes

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

Okay. I think it's fair to call that a limitation but not agonize over it. It might cause some cache misses based on changes in Python version or the package that defines a task, but we should be consistent across runs of the same code on the same Python version.

Under what circumstances are we actually hashing types? We're hashing values, so it seems like this should be moot for most cases.

String annotations will break the type-checking though...

@effigies
Copy link
Contributor

effigies commented Sep 8, 2023

Maybe we just treat strings as Any and raise a one-time warning?

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

Maybe we just treat strings as Any and raise a one-time warning?

We could do that, or attempt to evaluate them, and if that fails fallback to Any.

@tclose
Copy link
Contributor Author

tclose commented Sep 8, 2023

I reckon this is ready to merge now as the string annotations are probably best addressed in a separate PR

@effigies effigies merged commit 8579921 into nipype:master Sep 8, 2023
31 of 32 checks passed
@tclose tclose deleted the special-form-hash branch September 10, 2023 01:50
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.

2 participants