-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add typing to filepath
#4980
Add typing to filepath
#4980
Conversation
name, filepath, modname = file_item | ||
|
||
if not _worker_linter: | ||
raise Exception("Worker linter not yet initialised") |
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.
mpy
complains on the following two lines about the possibility that _work_linter
might be None
.
We currently already test for this, but do so with catching an AttributeError
on L73. See:
https://github.com/PyCQA/pylint/blob/fab2de272b3fc36dc4480d89840b8bfe0fbfbd0c/tests/test_check_parallel.py#L177-L182
I think making this error more explicit as mypy
wants makes sense. Although this is probably the wrong Exception
type.
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.
Not a review, just some thoughts.
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.
I wouldn't necessarily wait for #4973 to add typing.py
. You could also add it here. It shouldn't be too hard to resolve the merge conflicts in the end.
For Tuple[str, str, str]
it might even make sense to create a separate one. You should you by now that I like small PRs 😄
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@cdce8p I added the NamedTuple. However, doing this separately was (quite) awful because of the various new |
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.
I haven't commented on that before. A best practice when typing in python is to use the most generic type possible for arguments and the most concrete one for return types. I.e.
def func(var: Iterable[str]) -> List[str]:
...
If it doesn't matter if a list
, tuple
or something else is pass in as long as it's possible to iterate over it, it shouldn't matter to the type checker either.
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.
I really like where this is going!
pylint/lint/pylinter.py
Outdated
""" | ||
name, filepath, modname = file |
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.
Why do a tuple unpacking. With NamedTuple
you can access the attributes by name.
It might even make sense to just pass file
to set_current_module
/ get_ast
and do the attribute access there. A bit more refactoring though.
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.
I left the refactor for another time, since this is becoming quite a large PR.
One thing I noticed is some ambiguity between modname
and modpath
. They seem to be used for the same attribute. We currently use modpath
, is that okay? Or do you want to start using modname
?
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.
+1 for keeping the refactors for later :)
We should handle |
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Not sure if I agree here. This would probably lead us to having to add @cdce8p & @Pierre-Sassoulas Do you guys thinks your review is far enough for me to add the commit with test fixes as discussed in the PR description and shown in DanielNoord#10? |
Yes, also the migration to Path is also a huge endeavor with not a lot of clear benefit right now. Most |
3269364
to
4859288
Compare
for more information, see https://pre-commit.ci
…d/pylint into typing-filepath
Pull Request Test Coverage Report for Build 1241243212
💛 - Coveralls |
This now includes the relevant changes to the tests to make this work. As discussed in PR description I believe the tests check things that cannot happen in real world scenarios. The description includes some additional reasoning for this and a description of the changes to the tests. |
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
for more information, see https://pre-commit.ci
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Type of Changes
Description
This fails the test suite, but I think this might be because the test suite is testing something that doesn't happen in normal use of pylint. Please correct me if I am wrong but after investigating the call-chain I believe that almost all
filepath
's handled bypylint
arestr
(the only exception beingget_fatal_error_message()
). This presumes that no user directly callslinter.check()
as we do in the test suite.Of note is
lint.py_run()
, which I believe also does no runcheck()
before callingload_command_line_configuration
.The following reasoning leads me to believe that a normal use of
pylint
always creates astr
file path.load_command_line_configuration()
inpylint/config/option_manager_mixin.py
always returns aList[str]
. Therefore theargs
variable in the__init__
of theRun
class inpylint/lint/run.py
is always aList[str]
.pylint/lint/pylinter.py
thefiles_or_modules
argument tocheck()
is always aList[str]
. Which means that bothcheck_parallel()
and_check_files()
only handlestr
representations of paths.set_current_module()
andon_set_current_module()
in various other classes only get givenstr
.DanielNoord#10
This PR shows that with changes to the tests this PR can succeed. These changes are:
List[str]
test_worker_check_single_file_uninitialised()
catches the new explicitly defined exceptionget_fatal_error_message()
always gets aPath
as second argumentcheck_parallel()
always gets anIterable
These changes seem to follow the standard format of these arguments/variables in normal runs of
pylint
that are being skipped in the tests.