-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ignore type for mock.pyi inheritance from Any #1492
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
**Problem**: Any time I run `mypy`, I get an error like `<site-packages>/lib/mypy/typeshed/stdlib/3/unittest/mock.pyi:34: error: Class cannot subclass 'Any' (has type 'Any')` **Analysis**: python#1446 complains about the inheritance from `Any`, among other things, but what's relevant to this PR is where the use of `# type: ignore` is followed everywhere else this inheritance happens. I'm not sure if it's the "right" solution, but adding `# type: ignore` to `mock.pyi`'s use of `Any` resolves the error message I keep seeing. It also passes all of the [tests requested](https://github.com/python/typeshed/blob/master/README.md#running-the-tests). **Resolution**: I added the same `# type: ignore` comment to the inheritance from `Any` in `mock.pyi` that is used in other places that that inheritance is done. **Documentation**: No docs modified/added for this change. **Testing**: Ran the [tests](https://github.com/python/typeshed/blob/master/README.md#running-the-tests) locally on osx 10.11.6, and they all passed. **Impact**: Patch - ignoring an illegal type inheritance that appears to work but is flagged by mypy (and is ignored in other areas of typeshed code).
Since the change was so simple, I made it here and locally, instead of making a local branch and pushing it up. My local branch that I ran the tests on had the right spacing, and the online change didn't :-/ It does now.
I'd prefer to remove these to be more correct. Also putting an ignore makes it hard for mypy to pick them up to be removed eventually. People look to typeshed as a good example, and inheriting from @smessmer made the original addition of the I believe the type for it must be Any in some way, as it can return any type based on its usage, but again Im not familiar with it enough to say for sure. |
The OP, in his comprehensive post, does not mention what flags he passes to mypy, but I suspect he uses
|
Ooh, sorry, yes, I'm running I realize this "fix" is a little quick-and-dirty, but until a more correct solution is agreed upon, is there any downside to including it? With respect to people looking to typeshed for examples, the use of I would like to be able to run Ooh. Is there somewhere I could look for guidance on the right way to write a test for ensuring |
@toejough considering a better solution is not evident right now this fix is fine, but please add a TODO comment please. Also the issue I opened tracks all subclassing from Any. As for making typeshed mypy --strict safe, we are still working on that, and will likely need to ignore some errors. |
cool. added. |
Thanks! |
Problem:
Any time I run
mypy --strict --ignore-missing-imports
, I get an error like<site-packages>/lib/mypy/typeshed/stdlib/3/unittest/mock.pyi:34: error: Class cannot subclass 'Any' (has type 'Any')
Analysis:
#1446 complains about the inheritance from
Any
, among other things, but what's relevant to this PR is where the use of# type: ignore
is followed everywhere else this inheritance happens.I'm not sure if it's the "right" solution, but adding
# type: ignore
tomock.pyi
's use ofAny
resolves the error message I keep seeing. It also passes all of the tests requested.Resolution:
I added the same
# type: ignore
comment to the inheritance fromAny
inmock.pyi
that is used in other places that that inheritance is done.Documentation:
No docs modified/added for this change.
Testing:
Ran the tests locally on osx 10.11.6, and they all passed.
Impact:
Patch - ignoring an illegal type inheritance that appears to work but is flagged by mypy (and is ignored in other areas of typeshed code).