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

Conversation

Nurdok
Copy link
Member

@Nurdok Nurdok commented Mar 4, 2017

WIP, description to come.

@Nurdok
Copy link
Member Author

Nurdok commented Mar 4, 2017

This is still in the works, but I would appreciate any thoughts or comments from anyone who has a bit of time (esp. parser.py).

@sigmavirus24
Copy link
Member

I haven't looked at the code at all. My first question, however, is how does a Jedi AST differ from a Python stdlib AST? I ask specifically because Flake8 defaults to using a stdlib AST. It provides that parsed AST (doing it only once) to each plugin that traverses an AST. So if pydocstyle develops its own Flake8 plugin, it'll need to know how to take a stdlib AST and use that instead of a Jedi AST (or we'll have to work on converting Flake8 to using Jedi ASTs).

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

I'll probably have to do a few more passes to give you good feedback on the parser module rewrite.

setup.py Outdated
@@ -31,6 +31,9 @@
keywords='pydocstyle, PEP 257, pep257, PEP 8, pep8, docstrings',
packages=('pydocstyle',),
package_dir={'': 'src'},
install_requires=[
'jedi==0.9.0',
Copy link
Member

Choose a reason for hiding this comment

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

Please, let's not pin this. This causes unending headaches for users and downstream redistributors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eventually this will not be pinned. I temporarily pinned this because a new jedi was released while I was working on this, which broke some of my changes.

src/__init__.py Outdated
@@ -0,0 +1 @@
"""Pydocstyle - a docstring style checker."""
Copy link
Member

Choose a reason for hiding this comment

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

Is src/ meant to be a package? If yes, why? To be clear, I don't think src/ should be a package.

@@ -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.

@@ -0,0 +1 @@
"""Test for pydocstyle."""
Copy link
Member

Choose a reason for hiding this comment

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

py.test does not require an __init__.py and often recommends you don't make your tests module importable.

@@ -80,9 +94,16 @@ def _publicity(self):
return {True: 'public', False: 'private'}[self.is_public]

@property
def source_lines(self):
if '_source' in self._fields:
Copy link
Member

Choose a reason for hiding this comment

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

Will _source ever be in _fields now? Can't you just make this property a proxy for self.parent.source_lines now?


class DunderAll(Value):
"""A list of exported names in a module."""
_fields = 'names'.split()
Copy link
Member

Choose a reason for hiding this comment

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

>>> 'names'.split()
['names']

Why not simply do?

_fields = ['names']


class FutureImport(Value):
"""A list of __future__ imports in a module."""
_fields = 'name'.split()
Copy link
Member

Choose a reason for hiding this comment

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

Same question.

self.current.value.split('noqa: ')[1:])
elif self.current.value.startswith('# noqa'):
skipped_error_codes = 'all'
if 'noqa: ' in comment:
Copy link
Member

Choose a reason for hiding this comment

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

If I stripped the noqa logic into a separate library, would you use that instead?

@@ -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

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:
    ...

@samj1912
Copy link
Member

Closing this as it has been inactive for a while. Please feel free to re-open if this is still relevant.

@samj1912 samj1912 closed this Aug 29, 2020
@samj1912 samj1912 added the STALE-PR Label for stale PRs which have been closed due to inactivity. label Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STALE-PR Label for stale PRs which have been closed due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants