-
Notifications
You must be signed in to change notification settings - Fork 258
Do we need a standard way of silencing checkers? #16
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
Comments
The Hack approach would basically be:
The pylint approach has much more granularity but requires unique IDs to all checks. |
I like the simple with-statement. I think it is possible to write something that is both a decorator and a context manager. IIRC the unittest.mock package does this, so perhaps we could use the same name. When used as typing.off the cute name is fine; but after "from typing import off" it's too short IMO. (It turns off what?) |
The with statement is somewhat slow in CPython (the same applies to things like We could also have a comment that disables/enables all errors:
The comment should probably only extend until the end of the block that introduced it:
|
Hm. I'm not so keen on introducing more magic comments. See #35 |
So we're introducing magic comments, but we might want to have something for stub modules to declare that a module exports absolutely anything: https://mail.python.org/pipermail/python-ideas/2015-January/031381.html |
Mypy has a related concept for classes as an enhancement proposal. It would allow any attribute that's not explicitly defined to be accessed with type
Here are more syntax ideas:
I like the idea of having something like this, both for modules and classes. It would make it easy to define partial, work-in-progress stubs with static types only for the most commonly used features, and everything else would default to |
There's probably a mypy task left here, and there's a TODO for the class decorator in my typing.py, but the decision is made so I'm closing this:
|
The PEP draft is still somewhat unclear on this. Here's how I'd like Case 1: ignore until end of block
Case 2: ignore until end of file (special case of 1)
Case 3: ignore single line (comment on a non-empty line)
Case 4: ignore import statement If we ignore an import statement, don't try to type check the imported module and don't complain if we can't find it. Give type
|
So, is there still no way to ignore a small chunk of text? This would definitely work: x = 1
if True:
# type: ignore
# this always runs and never gets type checked
x = 'abc' but it feels ugly to me. I would like some kind of fake context manager: with ignore_type:
... but that would probably have speed issues. |
But how often do you really need that? Have you run into examples where you need this or are you just musing on potential use cases? The context manager feels too heavy to me (though if we want it, we could probably make the no_type_check decorator also act as a context manager, similar to some unittest decorators). Why couldn't you use |
It may be useful to have a way of saying "don't complain about this type error; trust me, I know what I'm doing". For example, consider this code:
A type checker would probably not allow assigning to an attribute of a function. However, sometimes programmers do this, and it works for user-defined functions. Maybe we could have a standard way of asking the type checker to shut up and ignore this particular warning only.
If we don't specify this in the PEP, there could end up being multiple tool-specific ways of doing this.
Apparently pylint supports something like this:
# pylint: disable=fixme
Hack also has something like this (example copied from Hack docs):
Link to relevant Hack docs: http://docs.hhvm.com/manual/en/hack.modes.unsafe.php
The text was updated successfully, but these errors were encountered: