-
Notifications
You must be signed in to change notification settings - Fork 57
Fix most mypy errors. #403
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #403 +/- ##
==========================================
- Coverage 87.30% 87.26% -0.05%
==========================================
Files 22 22
Lines 4262 4264 +2
Branches 839 840 +1
==========================================
Hits 3721 3721
- Misses 350 351 +1
- Partials 191 192 +1
Continue to review full report at Codecov.
|
Opinions on the two issues @adiroiban @mthuurne ?
|
Sorry for my slow responses; it's been a busy week and we had a bit of a heatwave here. I'll have a look now. |
The first error is weird: I can reproduce it under The second error I can reproduce in both setups. |
Ok. So let’s ignore them ? |
I want to dig a bit deeper first. |
The problem with |
I still don't understand why I don't get the error in my dev venv: I thought the reason might be because I have So ignoring the error would be the correct short-term solution here as well. You could link to python/typeshed#1269 as documentation of the problem. |
pydoctor/model.py
Outdated
@@ -808,6 +808,7 @@ def introspectModule(self, | |||
module_full_name = f'{package.fullName()}.{module_name}' | |||
|
|||
spec = importlib.util.spec_from_file_location(module_full_name, path) | |||
assert spec is not None, f"Cannot find spec for module {module_full_name} at {path}" |
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.
We should only use assert
if we can we guarantee that the condition is always true. If we're not that sure, it would be better to raise an exception instead.
I think there is at least one unlikely but possible scenario in which this condition is not true: if a file is deleted or moved between the moment its name is discovered and the moment it is introspected.
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.
A RuntimeError is OK ?
I don't think we should fix them all in this PR.
…tils related typing.
I've tried using the docutils-stubs as mentioned in this ticket but it's becoming a real headache, more than 50 errors that require a lot of additional checks in the restructuredtext module. I don't want to fix all mypy errors honestly. I will revert back to use Also the HTMLTranslator class has been moved to pydoctor.node2stan._PydoctorHTMLTranslator in #386 |
…ubs." This reverts commit bc3f2ac.
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.
🚢
|
||
commands = | ||
mypy \ | ||
--cache-dir="{toxworkdir}/mypy_cache" \ | ||
{tty:--pretty:} \ | ||
{posargs:pydoctor docs/epytext_demo} | ||
|
||
[testenv:mypy-docutils-stubs] | ||
description = run mypy with docutils-stubs (does not pass for now) | ||
; See: https://github.com/python/typeshed/issues/1269 |
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.
Do we want an issue for this repo as well, to track turning it on in CI when this is done?
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.
See #409
@@ -808,6 +808,8 @@ def introspectModule(self, | |||
module_full_name = f'{package.fullName()}.{module_name}' | |||
|
|||
spec = importlib.util.spec_from_file_location(module_full_name, path) | |||
if spec is None: | |||
raise RuntimeError(f"Cannot find spec for module {module_full_name} at {path}") |
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.
Can you do a test for this apparently untested case in a follow-up?
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.
Like @mthuurne was saying, this error is raised when a file is deleted or moved between the moment its name is discovered and the moment it is introspected. So honestly I don't know how to test such a case.
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 why FilePath
narrows down its interface to a single object which returns other objects, so you can pass a parameter along to the system under test. In the absence of such compositional design, the way to test this is to mock out spec_from_file_location
with patch
in a test.
I'd love to, but WYSIWYG in this case — I already have a recurring task in my personal task management system to review open source PRs as frequently as I can, and … this is about it ;) |
@mthuurne Can I merge that ? Thanks |
@mthuurne I will merge this PR now since it's blocking the CI from being green on all other branches. |
No description provided.