Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

WIP: Use Jedi as the underlying parser #240

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jedi==0.9.0
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest==3.0.2
pytest-pep8==1.0.6
mock==2.0.0
pathlib
-r runtime.txt
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
keywords='pydocstyle, PEP 257, pep257, PEP 8, pep8, docstrings',
packages=('pydocstyle',),
package_dir={'': 'src'},
install_requires=[
'jedi',
],
entry_points={
'console_scripts': [
'pydocstyle = pydocstyle.cli:main',
Expand Down
Empty file removed src/__init__.py
Empty file.
7 changes: 6 additions & 1 deletion src/pydocstyle/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ast
import string
import sys
import functools
import tokenize as tk
from itertools import takewhile
from re import compile as re
Expand Down Expand Up @@ -330,7 +331,7 @@ def check_unicode_docstring(self, definition, docstring):
For Unicode docstrings, use u"""Unicode triple-quoted strings""".

'''
if definition.module.future_imports['unicode_literals']:
if 'unicode_literals' in definition.module.future_imports:
return

# Just check that docstring is unicode, check_triple_double_quotes
Expand Down Expand Up @@ -680,6 +681,10 @@ def check(filenames, select=None, ignore=None, ignore_decorators=None):
try:
with tokenize_open(filename) as file:
source = file.read()
try:
source = source.decode('utf-8')
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this except should be more narrowly scoped. There are a surprising number of exceptions that can happen here and they depend on platform, how the python interpreter is compiled, etc.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To catch any exception use the except Exception, instead of except BaseException or just except.
Indicate the most specific exception type in except block.
For example:

# Bad
try:
    mapping[key]
except Exception:
    ...

# Better
try:
    mapping[key]
except KeyError:
    ...

pass
for error in ConventionChecker().check_source(source, filename,
ignore_decorators):
code = getattr(error, 'code', None)
Expand Down
Loading