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

gh-358: add static types and fix (some) mypy #308

Closed
wants to merge 41 commits into from
Closed

Conversation

paddyroddy
Copy link
Member

Closes #280. I anticipate this being a fair bit of work. I will use # type: ignore[ ] syntax throughout to minimise the initial work. I will raise a similar issue to #248 to address this.

@paddyroddy paddyroddy added enhancement New feature or request infrastructure Project infrastructure: dev tools, packaging, etc. maintenance Maintenance: refactoring, typos, etc. labels Oct 3, 2024
@paddyroddy paddyroddy self-assigned this Oct 3, 2024
@paddyroddy
Copy link
Member Author

paddyroddy commented Oct 4, 2024

Add a bunch of typing, proceed to increase the number of errors by 💯 😀

@paddyroddy
Copy link
Member Author

Paused in favour of #347

paddyroddy added a commit that referenced this pull request Oct 14, 2024
Closes #346. Working towards #188.

The main changes here have been:
- Remove all types in the docstrings in favour of proper static typing
(being added in #308)
- Switch from `numpydoc` to `sphinx.ext.napolean` due to
numpy/numpydoc#196

Have had to change the references to `[1]` rather than `[1]_` due to
this bug, sphinx-doc/sphinx#9689. Hopefully
this can be fixed in the future.

Example:
`glass.lensing.from_convergence`
<img width="781" alt="image"
src="https://github.com/user-attachments/assets/9b6fd087-686a-4a5c-a77a-f8a3ec9fc3e2">

Raised #350, #351.
@paddyroddy
Copy link
Member Author

Going to merge and address conflicts from #347

@paddyroddy paddyroddy mentioned this pull request Oct 14, 2024
paddyroddy added a commit that referenced this pull request Oct 14, 2024
Fixes #355, simplifying #308. Change all import of
`typing`/`collections.abc` to `import <x>` rather than
`from <x> import` syntax. This is useful because it is straightforward
to see at a glance where the `import` is coming from. Further, we have
both `numpy.random.Generator` and `collections.abc.Generator` in use -
so it separates them. I've also moved everything out of the
`TYPE_CHECKING` block, except from where `ruff` says we should.
paddyroddy added a commit that referenced this pull request Oct 14, 2024
Fixes #355, simplifying #308, xref #350. Change all import of
`typing`/`collections.abc` to `import <x>` rather than `from <x> import`
syntax. This is useful because it is straightforward to see at a glance
where the `import` is coming from. Further, we have both
`numpy.random.Generator` and `collections.abc.Generator` in use - so it
separates them. I've also moved everything out of the `TYPE_CHECKING`
block, except from where `ruff` says we should.
@paddyroddy paddyroddy changed the title gh-280: add mypy support gh-358: add static types and fix (some) mypy Oct 14, 2024
paddyroddy added a commit that referenced this pull request Oct 15, 2024
Adding `mypy` to a pre-existing codebase is never easy. I initially
attempted this in #308, but have since split this up into separate
issues:
- [x] #347
- [x] #356
- [ ] #358

In this PR, `mypy` is added but in order for CI to pass, the `# type:
ignore[]` syntax is used throughout. I didn't want to tackle these here
too (see #308) as it gets quite messy.

One thing I have done (following #356) is change every empty
`npt.NDArray` to `npt.NDArray[typing.Any]` (see #330), as this actually
results in fewer errors than leaving them all blank. Ideally, we'd like
to fill in as many of the `typing.Any` as possible - they're a bit
useless by themselves. However, that is not the priority for now. Plus,
I expect typing to change when #67 is tackled.
@paddyroddy
Copy link
Member Author

Merging in #359 now

@paddyroddy
Copy link
Member Author

Closing in favour of #368

@paddyroddy paddyroddy closed this Oct 15, 2024
@paddyroddy paddyroddy deleted the paddy/issue-280 branch October 15, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infrastructure Project infrastructure: dev tools, packaging, etc. maintenance Maintenance: refactoring, typos, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add mypy for type checking
1 participant