Comments (6)
This could be a warning since raising an exception isn't an error. @MikhailArkhipov how doable is this? Wouldn't decorators and metaclasses make this hard to get right? My worry would be the false-positives would just be too much if we can't make it reasonably robust.
from python-language-server.
@brettcannon
Raising an exception isn't an error, but not handing it is. That's when you need to show error.
About false positives.
This can be said almost about anything in python since it's dynamic. Consider this for example.
import conf
locals()['a'] = 1
print(a)
both pylint and pyflakes will complain
$ pylint delme.py
delme.py:1:0: E0401: Unable to import 'conf' (import-error)
delme.py:4:6: E0602: Undefined variable 'a' (undefined-variable)
$ pyflakes delme.py
delme.py:1: 'conf' imported but unused
delme.py:4: undefined name 'a'
But this successfully executes
$ python delme.py
1
Because conf is a virtual module created via .pth
file and because of locals manipulation. I don't know about everyone but I expect python linters to not be smart enough to know this (except locals and globals manipulation) and I would prefer to see error and not a warning in this case.
I think warning should be issued when code could possibly work and an error should be issued when there's no chance the code would work. But that's not how all popular python linters work. They all show errors on code that would work.
from python-language-server.
The problem is if you're developing a library then not catching an exception may be on purpose as you want the application to catch it and handle it, e.g. StopIteration
or something. That means we can't universally consider unhandled exceptions are an error.
And you're right that nearly everything could be considered a potential false-positive that isn't syntactically determined. Because of this we have so far not done any linter-style checks in the language server until we determine what we consider absolutely critical to the vast majority of users and what is better left up to third-party linters like flake8 and Pylint and not to duplicate their work if it isn't going to be useful to almost all of our users.
from python-language-server.
@brettcannon Somehow my post got lost, so I will have to repeat it briefly. My opinion on this is it doesn't really matter whether to show potential error as error or as a warning. What matters is to implement ability to ignore errors in the right way. And inserting special comments as many linters and PyCharm do is the wrong way to do it (it's probably okay to do that if linting is part of CI). Inserting comments for ignoring certain types of errors can prevent detecting new error when code is changed. The reason for the same type of error would be different. It should be reported to user, but it wouldn't. That's the area where you can be better than any available solution.
from python-language-server.
FYI pylint complains about this, but flake8 does not. But then pylint gives false-positives for the check.
def deco(func):
def wrapper(*args, **kwargs):
return do_some_stuff(42)
return wrapper
@deco
def do_some_stuff(real_arg):
pass
do_some_stuff(bad_arg='some')
Sample Pylint output:
************* Module other_example
other_example.py:1:0: C0111: Missing module docstring (missing-docstring)
other_example.py:1:0: C0111: Missing function docstring (missing-docstring)
other_example.py:2:0: W0613: Unused argument 'args' (unused-argument)
other_example.py:2:0: W0613: Unused argument 'kwargs' (unused-argument)
other_example.py:1:9: W0613: Unused argument 'func' (unused-argument)
other_example.py:7:0: C0111: Missing function docstring (missing-docstring)
other_example.py:7:18: W0613: Unused argument 'real_arg' (unused-argument)
other_example.py:11:0: E1123: Unexpected keyword argument 'bad_arg' in function call (unexpected-keyword-arg)
other_example.py:11:0: E1120: No value for argument 'real_arg' in function call (no-value-for-parameter)
from python-language-server.
@brettcannon
Using your example to show what I mean.
def deco(func):
def wrapper(*args, **kwargs):
return do_some_stuff(42)
return wrapper
@deco
def do_some_stuff(real_arg):
pass
#pylint: disable=E1120
do_some_stuff(bad_arg='some')
Now I change the code
def deco(func):
def wrapper(*args, **kwargs):
return do_some_stuff() # remove argument
return wrapper
@deco
def do_some_stuff(real_arg):
pass
#pylint: disable=E1120
do_some_stuff(bad_arg='some')
And pylint hides real problem now.
from python-language-server.
Related Issues (20)
- Run Microsoft.Python.LanguageServer standalone encountered a null pointer problem HOT 1
- Dataclass parameters with init=False HOT 2
- Allow language server to be used within markdown code blocks
- Tooltip shows setter docstring instead of GETTER docstring HOT 2
- Unnecessary Semicolon warning (no semicolon in file) HOT 4
- Configure workspace/didChangeConfiguration by default
- Couldn't start client Python Tools. Launching server using command /root/.vscode-server/extensions/ms-python.python-2021.6.944021595/languageServer.0.5.59/Microsoft.Python.LanguageServer failed. HOT 4
- Microsoft Python Language Server cannot be downloaded in WSL
- Error in vscode pylance output: `Stack overflow. Connection to server got closed. Server will not be restarted.` HOT 3
- The Python Tools server crashed 5 times in the last 3 minutes. The server will not be restarted. HOT 1
- Language server extraction failed
- The Python Tools server crashed 5 times in the last 3 minutes. The server will not be restarted. (Stack overflow error) HOT 4
- Can not download python language server HOT 2
- Connection to server got closed. Server will not be restarted. HOT 2
- Duplicate code warnings HOT 1
- Server Crash (Pylance) HOT 1
- Intellisense suggests imported names which should be considered an implementation detail. HOT 1
- opencv-python not autocompleting macos Big Sur using Anaconda, python 3.8.5 HOT 2
- Unable to find document, Object reference not set to an instance of an object HOT 9
- A way to silence 'x' is not accessed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-language-server.