diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2024-11-29 23:21:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-30 08:21:07 +0100 |
commit | 2a2d1989c1a2d8241822c7696ce2926a22949444 (patch) | |
tree | f888836a716309c0fbde3aa0a74c99d8be3e629e /.flake8 | |
parent | c6e292f55fc424e048a61347033c9b8fa533d8f5 (diff) | |
download | spack-2a2d1989c1a2d8241822c7696ce2926a22949444.tar.gz spack-2a2d1989c1a2d8241822c7696ce2926a22949444.tar.bz2 spack-2a2d1989c1a2d8241822c7696ce2926a22949444.tar.xz spack-2a2d1989c1a2d8241822c7696ce2926a22949444.zip |
`version_types`: clean up type hierarchy and add annotations (#47781)
In preparation for adding `when=` to `version()`, I'm cleaning up the types in
`version_types` and making sure the methods here pass `mypy` checks. This started as an
attempt to use `ConcreteVersion` outside of `spack.version` and grew into a larger type
refactor.
The hierarchy now looks like this:
* `VersionType`
* `ConcreteVersion`
* `StandardVersion`
* `GitVersion`
* `ClosedOpenRange`
* `VersionList`
Note that the top-level thing can't easily be `Version` as that is a method and it
returns only `ConcreteVersion` right now. I *could* do something fancy with `__new__` to
make `Version` a synonym for the `ConcreteVersion` constructor, which would allow it to
be used as a type. I could also do something similar with `VersionRange` but not sure if
it's worth it just to make these into types.
There are still some places where I think `GitVersion` might not be handled properly,
but I have not attempted to fix those here.
- [x] Add a top-level `VersionType` class that all version types extend from
- [x] Define and document common methods and rich comparisons on `VersionType`
- [x] Replace complicated `Union` types with `VersionType` and `ConcreteVersion` as needed
- [x] Annotate most methods (skipping `__getitem__` and friends as the typing is a pain)
- [x] Fix up the `VersionList` constructor a bit
- [x] Add cases to methods that weren't handling all `VersionType`s
- [x] Rework some places to clarify typing for `mypy`
- [x] Simplify / optimize _next_version
- [x] Make StandardVersion.string a property to enable lazy comparison
Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to '.flake8')
0 files changed, 0 insertions, 0 deletions