Skip to content

Improve type hint annotations in plasmapy.particles - #2429

Closed
namurphy wants to merge 22 commits into
PlasmaPy:mainfrom
namurphy:particles-typing-dec
Closed

namurphy wants to merge 22 commits into
PlasmaPy:mainfrom
namurphy:particles-typing-dec

Conversation

@namurphy

Copy link
Copy Markdown
Member

Description

This PR makes some incremental improvements to typing in plasmapy.particles with help from mypy.

Motivation and context

Instead of adding types all at once, it's preferable to add them in small, more reviewable chunks.

Related issues

#268, #2424

@github-actions github-actions Bot added plasmapy.particles Related to the plasmapy.particles subpackage CI Related to continuous integration linters Code linters and autoformatters labels Dec 27, 2023
Comment thread .pre-commit-config.yaml Resolved
@codecov

codecov Bot commented Dec 27, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (75bf724) 96.92% compared to head (4e2f604) 96.91%.
Report is 2 commits behind head on main.

Files Patch % Lines
plasmapy/particles/decorators.py 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2429      +/-   ##
==========================================
- Coverage   96.92%   96.91%   -0.02%     
==========================================
  Files         104      104              
  Lines        9153     9169      +16     
==========================================
+ Hits         8872     8886      +14     
- Misses        281      283       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

arg: ParticleLike,
*,
mass_numb: Optional[Integral] = None,
mass_numb: Optional[int] = None,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised that objects from numbers aren't intended to be used with static type checking with mypy (PEP 484). There are constructs like typing.SupportsInt which can be used.

plasmapy/particles/tests/test_atomic.py:417: note: Types from "numbers" aren't supported for static type checking
plasmapy/particles/tests/test_atomic.py:417: note: See https://peps.python.org/pep-0484/#the-numeric-tower
plasmapy/particles/tests/test_atomic.py:417: note: Consider using a protocol instead, such as typing.SupportsFloat

@namurphy

Copy link
Copy Markdown
Member Author

I think a problem here is that since @particle_input is not sufficiently typed, then functions that are decorated by it will not be sufficiently typed either.

@namurphy

namurphy commented Jan 5, 2024

Copy link
Copy Markdown
Member Author

This is partially superseded by #2443.

@namurphy

Copy link
Copy Markdown
Member Author

This one got superseded by or jumbled together with some other PRs, so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Related to continuous integration linters Code linters and autoformatters plasmapy.particles Related to the plasmapy.particles subpackage static type checking testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant