-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ability to configure flags for a module from a comment within it #2938
Comments
I can see the value of this, in part because this was my original idea for per-file configuration options. The options that can be set within a file should probably be named identically to either the command-line options or the config file options to avoid redundancy. I'd also spell the comment like this:
We could also support multiple options per line ( For example:
(There already is If we'd use the config file syntax, it would perhaps look like this (one option per line):
I think that the options should be global to a file (i.e. no per-function options), and would be applied after config file options (but the config file would still be consulted as well). |
OK we need to do this, I think, because our internal mypy.ini is thousands of lines long and I want to start doing things that would make it longer. My proposal is to allow both multiple options on a line and multiple lines. I prefer command line style, since writing So things would look like
|
This is essentially in preparation for a proof-of-concept implementation of #2938 I am working on, which will want to call into this code from build, and a build -> main dependency seems wrong.
Implements line configuration using '# mypy: ' comments, following the blueprint I proposed in #2938. It currently finds them just using a regex which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Examples of what it looks like in the tests. Fixes #2938. Thoughts?
While I initially gave this a thumbs-up, on second thought I am not comfortable with the choice of using comma+space as separator. I also agree that a space is less than ideal. How about one of the following?
I slightly favor (2). |
This is essentially in preparation for a proof-of-concept implementation of #2938 I am working on, which will want to call into this code from build, and a build -> main dependency seems wrong.
Implements line configuration using '# mypy: ' comments, following the blueprint I proposed in #2938. It currently finds them just using a regex which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Examples of what it looks like in the tests. Fixes #2938. Thoughts?
Implements line configuration using '# mypy: ' comments, following the blueprint I proposed in #2938. It currently finds them just using a regex which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Examples of what it looks like in the tests. Fixes #2938. Thoughts?
Yeah let's do option (2). Honestly I was mostly just trying to get out of writing the delimiter-quote-parsing code but (like every other part of this PR) it just wasn't actually that bad. |
Implements line configuration using '# mypy: ' comments, following the blueprint I proposed in #2938. It currently finds them just using a regex which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Examples of what it looks like in the tests. Fixes #2938. Thoughts?
I like (2), since it seems to be the most general -- it allows both commas and semicolons as option values. I think that it also looks pretty nice in the common case. Maybe also allow escapes for double quotes and maybe things like newlines (just in case)? |
My inclination is to not bother with more complicated escaping syntax until we want to add options that could take advantage of it, but it wouldn't be hard to support also. |
The main potential use case for escaping that I can imagine is per-module flags to mypy plugins, which we don't support at the moment. So it seems fine to not support it for now. I couldn't even find an example where quoting the value would be useful, since none of the options where this is useful seem to be per-module options. |
Well, |
(Oh wait, never mind. You were talking about escaping quotes inside quoted strings. Yeah, I suppose we don't need that.) |
Implements line configuration using '# mypy: ' comments, following the the discussion in #2938. It currently finds them in a pretty primitive manner which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Documentation to come in a follow-up PR. Fixes #2938.
This is essentially in preparation for a proof-of-concept implementation of python#2938 I am working on, which will want to call into this code from build, and a build -> main dependency seems wrong.
Implements line configuration using '# mypy: ' comments, following the the discussion in python#2938. It currently finds them in a pretty primitive manner which means it is possible to pick up a directive spuriously in a string literal or something but honestly I am just not worried about that in practice. Documentation to come in a follow-up PR. Fixes python#2938.
I would like to be able to use some syntax like
to turn on all the useful stricter-checking flags, like
--disallow-subclassing-any
--warn-return-any
--disallow-untyped-calls
--strict-optional
Not totally sure what each one does. Ideally we'd turn them all on globally, but ideally all our code would already be typed, and we don't live in that world. I'd prefer this to our current mypy.ini for a few reasons:
I suppose we'll still want to introduce new flags over time - to make stricter checking opt in so large codebases don't have to migrate all at once. So either mypy standardizes ways to refer to a few flags (e.g. the first 3 could be called --strict-any? or --no-implicit-any like typescript?) or we could allow configuring these aliases in mypy.ini. I think I'm a fan of the former - provides more standardization across codebases.
The text was updated successfully, but these errors were encountered: