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

Improve Pylance support for Raster #68

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

gmgunter
Copy link
Member

This PR supersedes #66. Refer to that PR for background.

The approach in the previous PR satisfied Pylance but ran into issues with Mypy. This PR instead tries to resolve the issue by including a typing stub (.pyi) file that exposes the Raster class for static analysis tools like Pylance and Mypy without affecting the runtime behavior.

The new approach seems to work well, except Mypy now complains about the new stub file conflicting with the existing .py file:

src/snaphu/io/__init__.pyi: error: Duplicate module named "snaphu.io" (also at "src/snaphu/io/__init__.py")

This seems to be related to the way that pre-commit passes arguments to Mypy. When running Mypy on a directory containing both .py and .pyi files, it runs fine. But when passing individual .py and .pyi files with identical module names as separate arguments to Mypy (as pre-commit does) it raises the above error.

Since this issue is largely related to the particular way that pre-commit runs Mypy, I think a reasonable bandaid is to simply exclude the conflicting .py file from the pre-commit hook.

Closes #66

Pylance seemed to be failing to find the definition of
`snaphu.io.Raster` (presumably due to the heterodox way in which it's
exported), which manifested in VSCode tooltips implicitly treating the
type as equivalent to `Any`.

This update tries to resolve the issue by including a typing stub (.pyi)
file that exposes the Raster class for static analysis tools like
Pylance and Mypy. The runtime behavior is unaffected.

When run via pre-commit, Mypy complains about the new stub file

```
src/snaphu/io/__init__.pyi: error: Duplicate module named "snaphu.io" (also at "src/snaphu/io/__init__.py")
```

This apparently has to do with how what arguments are passed to mypy --
when its passed a directory that contains both .py and .pyi files, it
runs without issues, but when it's passed both files as separate
positional arguments, it complains about duplicate modules. Pre-commit
runs mypy the latter way, so we add a workaround by excluding the
particular .py file from that pre-commit hook.
Copy link

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.37%. Comparing base (c7780bb) to head (1cf45e7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   92.79%   93.37%   +0.57%     
==========================================
  Files           9        9              
  Lines         472      468       -4     
==========================================
- Hits          438      437       -1     
+ Misses         34       31       -3     

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

@gmgunter gmgunter merged commit 40a7e9d into isce-framework:main Jun 10, 2024
13 checks passed
@gmgunter gmgunter deleted the pylance-raster-stub branch June 10, 2024 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant