AMICI-dev / AMICI

Advanced Multilanguage Interface to CVODES and IDAS
https://amici.readthedocs.io/
Other
108 stars 30 forks source link

Add stacklevel to warnings #2421

Closed dweindl closed 5 months ago

dweindl commented 5 months ago

Make it easier to find out where warnings originate from.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.60%. Comparing base (6b05ddd) to head (7bdeb07).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/graphs/tree.svg?width=650&height=150&src=pr&token=1bt9lbspzk&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev)](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) ```diff @@ Coverage Diff @@ ## develop #2421 +/- ## =========================================== - Coverage 77.63% 77.60% -0.03% =========================================== Files 324 324 Lines 20913 20913 Branches 1464 1464 =========================================== - Hits 16236 16230 -6 - Misses 4674 4680 +6 Partials 3 3 ``` | [Flag](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | `73.38% <ø> (-0.03%)` | :arrow_down: | | [cpp_python](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | `34.12% <ø> (ø)` | | | [petab](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | `36.70% <ø> (ø)` | | | [python](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | `72.14% <ø> (-0.03%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev) | Coverage Δ | | |---|---|---| | [python/sdist/amici/logging.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Flogging.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL2xvZ2dpbmcucHk=) | `79.16% <ø> (ø)` | | | [python/sdist/amici/parameter\_mapping.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fparameter_mapping.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3BhcmFtZXRlcl9tYXBwaW5nLnB5) | `0.00% <ø> (ø)` | | | [python/sdist/amici/petab/conditions.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fpetab%2Fconditions.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3BldGFiL2NvbmRpdGlvbnMucHk=) | `97.43% <ø> (ø)` | | | [python/sdist/amici/petab\_objective.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fpetab_objective.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3BldGFiX29iamVjdGl2ZS5weQ==) | `0.00% <ø> (ø)` | | | [python/sdist/amici/petab\_simulate.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fpetab_simulate.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3BldGFiX3NpbXVsYXRlLnB5) | `0.00% <ø> (ø)` | | | [python/sdist/amici/petab\_util.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fpetab_util.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3BldGFiX3V0aWwucHk=) | `0.00% <ø> (ø)` | | | [python/sdist/amici/sbml\_import.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fsbml_import.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3NibWxfaW1wb3J0LnB5) | `78.77% <ø> (ø)` | | | [python/sdist/amici/swig\_wrappers.py](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421?src=pr&el=tree&filepath=python%2Fsdist%2Famici%2Fswig_wrappers.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev#diff-cHl0aG9uL3NkaXN0L2FtaWNpL3N3aWdfd3JhcHBlcnMucHk=) | `92.42% <ø> (ø)` | | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/AMICI-dev/AMICI/pull/2421/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AMICI-dev)
FFroehlich commented 5 months ago

Hmm, is it not possible to manage this using a context manager? Seems rather difficult to keep stack levels cohesive throughout the package.

dweindl commented 5 months ago

Hmm, is it not possible to manage this using a context manager? Seems rather difficult to keep stack levels cohesive throughout the package.

Finding the precise frame / code location where some deprecated argument is introduced is overkill in my opinion.

For the module-level deprecation warnings, stacklevel=2 always makes sense, because this will show the location of the deprecated import statement.

FFroehlich commented 5 months ago

Hmm, is it not possible to manage this using a context manager? Seems rather difficult to keep stack levels cohesive throughout the package.

Finding the precise frame / code location where some deprecated argument is introduced is overkill in my opinion.

For the module-level deprecation warnings, stacklevel=2 always makes sense, because this will show the location of the deprecated import statement.

Yes, my concern is more that the next time we add a warning, we will forget to add the stacklevel=2 argument.

dweindl commented 5 months ago

my concern is more that the next time we add a warning, we will forget to add the stacklevel=2 argument.

Oh, no worries, I'm happy to add a reminder: https://docs.astral.sh/ruff/rules/no-explicit-stacklevel/