Add option to selectively disable --disallow-untyped-calls#15845
Add option to selectively disable --disallow-untyped-calls#15845ilevkivskyi merged 4 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
3eea8d1 to
47f2487
Compare
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
Thanks, this seems useful! Not a full review.
docs/source/command_line.rst
Outdated
|
|
||
| .. code-block:: python | ||
|
|
||
| # mypy --disallow-untyped-calls --untyped-call-exception=foo --untyped-call-exception=bar.A |
There was a problem hiding this comment.
Maybe also use a real third-party package in the example, such as numpy?
mypy/checkexpr.py
Outdated
| assert object_type is not None | ||
| fullname = self.method_fullname(object_type, member) | ||
| if not fullname or not any( | ||
| fullname.startswith(p) for p in self.chk.options.untyped_call_exception |
There was a problem hiding this comment.
Make sure the exception re doesn't apply to retry, i.e. the startswith operation should probably be at module name component level.
docs/source/config_file.rst
Outdated
| disallow_untyped_calls = True | ||
| untyped_call_exception = some.library | ||
|
|
||
| .. confval:: untyped_call_exception |
There was a problem hiding this comment.
This seems useful, but I'm not sure about the name of the option. Maybe we can come up with a better name? I don't any suggestions right now, but I'll think about this later.
There was a problem hiding this comment.
I also struggled some time with this. I would propose to not spend much time on this. People who want this will probably search for "mypy untyped call" or similar, so including these words in the option name should be good enough. So if you have a better idea, then I will be happy to update, otherwise let's just move on.
There was a problem hiding this comment.
Fwiw I'd go with untyped_call_allowlist. Clearly conveys the type as well ;-)
There was a problem hiding this comment.
This is what I considered at first, but then how wold we call corresponding command line option? --untyped-call-allowlist? All other options like --always-true, --always-false, --enable-error-code, --disable-error-code etc, are singular and should be repeated. So I would say we should try to follow this pattern. Finally, from reading comments in the issue, it looks like most people will need just 1 or maybe 2 exceptions, not more.
| :type: comma-separated list of strings | ||
|
|
||
| Selectively excludes functions and methods defined in specific packages, | ||
| modules, and classes from action of :confval:`disallow_untyped_calls`. |
There was a problem hiding this comment.
Mention that this also applies to submodules of packages (i.e. everything inside that prefix).
docs/source/command_line.rst
Outdated
| This flag allows to selectively disable :option:`--disallow-untyped-calls` | ||
| for functions and methods defined in specific packages, modules, or classes. | ||
| Note that each exception entry acts as a prefix. For example (assuming there | ||
| are no type annotations for ``numpy`` available): |
There was a problem hiding this comment.
Numpy's probably not a great example here, as they ship with a py.typed file these days and have pretty complete type annotations. Maybe one of matplotlib, requests or TensorFlow might be a better example? Third-party stubs exist for all three packages, but none of them ships with a py.typed file
There was a problem hiding this comment.
Any example of a popular library might become a bad example over time, maybe limit ourselves to something generic like third_party_lib?
There was a problem hiding this comment.
Yeah, let's use some generic name.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
IIUC the only remaining question now is the name of the new flag. I propose that instead of keeping this open indefinitely, merge this as is, and then think about it until the next release. It will be easy to rename it if a better idea appears. If there are no objections, I am going to merge this tomorrow or Monday. |
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks, this is a nice feature. Agreed we can merge. How do you feel about just --untyped-call-allow? I like using "allow" because it's a verb we use in a lot of places and because exception makes me think of the language feature
|
Yes,
|
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Great, I like it! |
|
Hey, I just want to say, god bless you guys for adding this feature. I started using mypy last week and have thought that there has to be a way to do what untyped_calls_exclude does. It's hard to believe that this was only added this recently. |
|
For those looking for a [tool.mypy]
strict = true
untyped_calls_exclude = [
"skimage"
]This ignores all errors from missing type annotations in the |
Fixes #10757
It is surprisingly one of the most upvoted issues. Also it looks quite easy to implement, so why not. Note I also try to improve docs for per-module logic for
disallow_untyped_calls, as there is currently some confusion.