-
Notifications
You must be signed in to change notification settings - Fork 9
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-355: consistent use of typing
and collections.abc
#356
Conversation
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.
"if TYPE_CHECKING:", | ||
"if typing.TYPE_CHECKING:", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is important, we might potentially want to add both in case someone doesn't use the format this PR is trying to enforce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @paddyroddy! Looks good!
I really don't like this change, as it goes against established typing practice (e.g., https://typing.readthedocs.io). |
It is how I've done it in all my work with ARC. Explicit imports make it so much easier to know where something comes from. However, this can be undone - but preferably after #359 #308 |
It also clutters the namespace https://softwareengineering.stackexchange.com/a/187432/320391 |
Only if the imports are not guarded by the future import and |
Have raised #361 |
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.
Fixes #355, simplifying #308, xref #350. Change all import of
typing
/collections.abc
toimport <x>
rather thanfrom <x> import
syntax. This is useful because it is straightforward to see at a glance where theimport
is coming from. Further, we have bothnumpy.random.Generator
andcollections.abc.Generator
in use - so it separates them. I've also moved everything out of theTYPE_CHECKING
block, except from whereruff
says we should.