Giter Site home page Giter Site logo

Comments (8)

peterjc avatar peterjc commented on August 22, 2024

I agree - this plugin is a great big hack to glue docutils into flake8.

If you know lots about AST, you could be very well placed to clean this up. If you want to work on this, I would be happy to look at a pull request.

from flake8-rst-docstrings.

domdfcoding avatar domdfcoding commented on August 22, 2024

From what I can tell (having used AST very briefly yesterday), the docstring is stored as an ast.Expr object in the "body" of an ast.FunctionDef object representing the function. Classes are presumably represented differently in the AST.

From the ast.Expr object the following can be accessed:

  • the docstring text, via the .value.s attribute
  • the lineno, via the .lineno attribute
  • the col_offset, the the .col_offset attribute

I've put together a rough example of how to extract the docstrings from an AST, modelled after Anthony Sottile's flake8_2020 plugin, so I assume this is the correct way to do it. I imagine this could then be passed to docutils for it to do its thing?

I'll try and explore this further over the weekend.

from flake8-rst-docstrings.

peterjc avatar peterjc commented on August 22, 2024

That sounds very promising @domdfcoding 👍

from flake8-rst-docstrings.

peterjc avatar peterjc commented on August 22, 2024

Pull request #33 will clean this up a lot but just importing the pydocstyle parser, but does not address this point directly: We still reparse the Python file when flake8 already did it and can share the AST.

from flake8-rst-docstrings.

peterjc avatar peterjc commented on August 22, 2024

I made some time to look at this today, what do you think of the code on PR #35 using the AST?

from flake8-rst-docstrings.

skirpichev avatar skirpichev commented on August 22, 2024

Looks good. I've noticed some workarounds for ancient python versions. Maybe it's time to drop this?

from flake8-rst-docstrings.

peterjc avatar peterjc commented on August 22, 2024

Yeah, the workaround for Python 3.3 and 3.4 was trivial though, so I decided to leave it in for now. I'm expecting and hoping no one complains about my dropping Python 2.7 support yesterday.

from flake8-rst-docstrings.

peterjc avatar peterjc commented on August 22, 2024

Closed by #35 and the release of v0.2.0, thank you for the suggestion.

from flake8-rst-docstrings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.