-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add the ability to specify mypy options in source file comments #3388
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
mypy/options.py
Outdated
for flag in match.group(1).split(','): | ||
flag = flag.strip() | ||
if flag in self.PER_MODULE_OPTIONS: | ||
updates[flag] = True |
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.
Also it would be good to show an error if flag
is not in self.PER_MODULE_OPTIONS
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.
Yeah, good call.
I'm working now on fixing the tests, and on making the |
This seems related to #1235 |
I'm a bit mystified about why the two tests that are failing are. There doesn't seem like there should be anything ambiguous about the |
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 not a full review. I expect that the test failure is because you've disturbed the import order (there are some import cycles in mypy).
mypy/build.py
Outdated
from mypy.parse import parse | ||
from mypy.stats import dump_type_stats | ||
from mypy.types import Type | ||
from mypy.version import __version__ | ||
|
||
if 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.
Did you see the comment on line 25 above? Please use MYPY instead. (It will somehow not fail in the tests but it will fail in real life when mypy is running on 3.5.1, because TYPE_CHECKING is not in that version's typing.py.)
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.
Oops. Yes, I definitely missed the earlier comment. I'll fix the uses of TYPE_CHECKING
that I added.
There seems to be something very wrong with this PR. Why did you do all the refactoring? It would be much easier to review and easier to understand if you made a minimal change rather than moving all that code into options. |
@gvanrossum: I can certainly roll back the options parsing change, if that would make review easier. The reason that I did it was to make it so that the per-file options could actually use the same format as the CLI. Sadly, parsing those options happened in EDIT: I also tried moving the option parsing into a separate package, but ended up with the same set of circular imports, with just an additional step in the chain. Making the imports of |
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.
Maybe you can first submit a PR that doesn't change any semantics but paves the way for the changes/sharing you have in mind? Then that would hopefully be where we debug why "mypy mypy" fails (which is why the tests are failing).
Sorry, I'm not sure I understand. You'd like me to separate the re-jiggering of |
Yeah, I think that's what Guido is asking for. (And I agree -- it'd be much easier to review if those were separate PRs.) I'm a concerned about the correctness of implementing this functionality with a regex -- it would pick up these pragmas from a docstring, for example. It's more work, but I think the correct way forward here is to extend Also, I actually think it would be better here to use the config file format rather than that of command line options, because this directly corresponds to setting a per-file option in the config file. Config file and command line options are not exactly the same -- for example, there's no way to specify |
@ddfisher: Ok, I'll make a separate pr for moving |
@ddfisher: To be honest, part of the reason for using regexes to pull the initial lines out was because the per-file options updates happen well before the files are actually parsed. Using Following the same rules with the config file format, I think I'd instead look for something like:
My proposal would be that the If we do go with this, we'd need to at least move |
Maybe move it to a new file to avoid circular imports? |
@gvanrossum: Yeah, I tried that when I moved In aid of that, I'm going to rebase-out the last few commits of this branch, since they are no longer relevant to this particular attempt (and are instead covered by #3391, if we go that direction). Edit: Sadly, |
46bc9bf
to
96638ed
Compare
@ddfisher, @gvanrossum: Ok, I've completed a much more minimal extraction of Edit: apparently, I was a bit early in declaring victory on the tests. |
With regards to using typed_ast: there aren't currently any per-file options that affect parsing of a file, so that won't be an issue. With regards to the format: could you create an issue with a proposal for the format? I think there may be a decent amount of discussion that will need to happen before we decide on something, and I don't want you to have to make big changes to this PR every time the prevailing wind shifts. |
@cpennington Should we close this? There has been no activity for 5 months, and the specific design implemented here seems to be superseded by the outcome of the discussion in #3432 (the conclusion there was to use comments of the form
We should probably also close #3391. |
Yeah, let's close this. I can pick it up again and rebase/fix it whenever I get time again. |
This still needs work on things like docs and tests, but it seems to basically function.
@gnprice, @ambv: I think this more or less covers what we talked about in the open space today.