-
Notifications
You must be signed in to change notification settings - Fork 5
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
Reimplement DataAccessor
for easier testing & validation
#53
Comments
DataAccessor
DataAccessor
for easier testing & validation
How can I reproduce those Mypy errors from bash? E.g. |
Seems to work for me: $ hatch run lint:mypy
sourcefinder/accessors/requiredatts.py:64: error: Need type annotation for "required_atts" (hint: "required_atts: set[<type>] = ...") [var-annotated]
sourcefinder/utility/containers.py:55: error: Signatures of "__iadd__" and "__add__" are incompatible [misc]
sourcefinder/accessors/dataaccessor.py:90: error: "DataAccessor" has no attribute "tau_time" [attr-defined]
sourcefinder/accessors/dataaccessor.py:91: error: "DataAccessor" has no attribute "freq_eff" [attr-defined]
sourcefinder/accessors/dataaccessor.py:92: error: "DataAccessor" has no attribute "freq_bw" [attr-defined]
sourcefinder/accessors/dataaccessor.py:93: error: "DataAccessor" has no attribute "taustart_ts" [attr-defined]
sourcefinder/accessors/dataaccessor.py:94: error: "DataAccessor" has no attribute "url" [attr-defined]
sourcefinder/accessors/dataaccessor.py:95: error: "DataAccessor" has no attribute "beam" [attr-defined]
sourcefinder/accessors/dataaccessor.py:96: error: "DataAccessor" has no attribute "beam" [attr-defined]
sourcefinder/accessors/dataaccessor.py:97: error: "DataAccessor" has no attribute "beam" [attr-defined]
sourcefinder/accessors/dataaccessor.py:98: error: "DataAccessor" has no attribute "centre_ra" [attr-defined]
sourcefinder/accessors/dataaccessor.py:99: error: "DataAccessor" has no attribute "centre_decl" [attr-defined]
sourcefinder/accessors/dataaccessor.py:100: error: "DataAccessor" has no attribute "pixelsize" [attr-defined]
sourcefinder/accessors/dataaccessor.py:101: error: "DataAccessor" has no attribute "pixelsize" [attr-defined]
sourcefinder/accessors/dataaccessor.py:112: error: "DataAccessor" has no attribute "wcs" [attr-defined]
sourcefinder/accessors/lofarhdf5image.py:62: error: "LofarHdf5Image" has no attribute "header" [attr-defined] What do you see exactly? Maybe you can explicitly specify the source directory: |
|
And the same for I guess I should activate the virt env defined by |
You should do this outside of any other environments you have.
I think you need to install type stubs for the dependencies. Try this: |
$ hatch env show
Standalone
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Type ┃ Dependencies ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ default │ virtual │ │
├─────────┼─────────┼──────────────┤
│ test │ virtual │ pytest │
│ │ │ pytest-cov │
├─────────┼─────────┼──────────────┤
│ lint │ virtual │ black │
│ │ │ flake8 │
│ │ │ mypy │
│ │ │ ruff │
└─────────┴─────────┴──────────────┘ |
Thanks. However,
|
But works fine once part of the e711711 commit is reverted. |
I guess you are suggesting that a solution would involve removing RequiredAttributesMetaclass, since this kind of machinery is an overkill? Removing it may not only affect unit tests in PySE, but also in TraP. |
@suvayu How about a solution using the property decorator? |
It depends on the kind of validation you want to do. If they are just type based, I would use |
Please don't revert this commit. I could recommend the correct resolution if you post the error. My guess is, because this changes the build a bit, you just need to run the build step once. Try this |
Indeed after issuing |
If you want to fix this, clone https://github.com/transientskp/trap-test-data, and put the I'll set this up properly when I have more time. |
That worked indeed! |
The motivation for adding the
I need to think about this longer, since this means that the precursor of property was used until nine years ago and replaced by this |
Hi @HannoSpreeuw, I think what would help in the decision is to get an overview of how derived classes are being used, and more importantly, what functionality does this base class offer? |
… metaclass=RequiredAttributesMetaclass), i.e. DataAccessor inheriting from RequiredAttributesMetaclass is an overkill, since RequiredAttributesMetaclass does nothing more than checking for required attributes. requiredatts.py can be removed and DataAccessor can be turned into a dataclass, which will have the required arguments declared.
This was closed automatically, because of the line |
From Mypy:
This is because the base class uses a custom
metaclass
, and the base class doesn't really have these defined, but some methods use them (e.g.extract_metadata
).This kind of enforcement of API behaviour is much more cleanly achieved by using either of the following,
NamedTuple
,dataclass
es, orattrs
.The text was updated successfully, but these errors were encountered: