-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New setting "user_builtins_name": Ignore specific "name-defined" errors #18932
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
I assume using Maybe better than a list of names to ignore would be |
Cumbersome is a word to use, but Hacky and Over-exagered seems to me a better descriptors. At first, I thought that the solution you suggested was that I import the more than 2000 line But no, that worst than that since your suggestion need to import the +700 files of the native CPython/mypy??? For 2 functions??? Why do that for a such small change ??? O_o So, I'm sure there are projects that are able and determined to do this kind of thing, but it's certainly because they have a very good reason to do it, like probably using custom versions of CPython/mypy. But that's not the case for everyone, especially given the disproportionate size ratio between the files added and the modifications specific to this project. Not to mention the maintenance that would have to be done in the event of a python version change. No, you idea completly miss the use case for small and medium-sized projects, and probably the almost totality of any projects of any size, with a absurdly over-exagered way to solve a simple and small problem. So Yes, checking the types for the custom builtins functions would be a must-have, and that's why the support of (and I don't understand why you propose to use "custom_typing_module", their is no type change implie in my proposal) |
A trivial implementation of cat __builtins__.pyi >>.venv/lib/python*/site-packages/mypy/typeshed/stdlib/builtins.pyi If you run an automated CI pipeline, such monkey-patching will likely be much easier than using typeshed as a git submodule and saving your modifications. (yes, I'm mostly joking, but for closed-source codebase with a small team... may work just fine) That will only support really simple cases (like variables annotated with builtin types) because builtins are special-cased, but may be good enough to not warrant I'm, however, +1 on supporting some variant of I can suggest to add a Alternatively, it may be Either option will be intended for advanced users and subject to breaking changes. Supplying something bad there may cause any sorts of mypy crashes down the road. |
Append your custom builtins data to the stub in mypy packages? Clever. Still a stopgap solution, patching For the radicality of Else, I finaly manage to implement the support of |
Feature
Adding a setting "user_builtins_name", or "builtins", that is a array of strings for which the error
[name-defined]
is ignored.Pitch
It is possible to extend the list of builtins function, which can be very useful in some projects as we no longer need to import this function if it's used extensively in the rest of the project.
Example:
Sadly, mypy don't support such exotic things. There is two solution:
The first would be the best, but also the harder to implement. The second would be easier to implement, but some ignored 'name-defined' error could be legitimate depending on the import and call stack. But since the very exotic and niche feature, the risks are low and we can assume that the user know what he do when he use this settings.
The use of a setting name that contain the word 'builtins' allows to explicitly specify the user case of such setting (when a generic "ignore_name_defined" could be misinterpreted and so misused)
Related Issues
#7931
The text was updated successfully, but these errors were encountered: