Giter Site home page Giter Site logo

Comments (8)

jquast avatar jquast commented on July 23, 2024

Here is a PR for another tool implementing precisely that, landscapeio/prospector#71

from pydocstyle.

The-Compiler avatar The-Compiler commented on July 23, 2024

There's tokenize.detect_encoding and in later Python versions, tokenize.open which is probably a lot simpler than that PR 😉

from pydocstyle.

jquast avatar jquast commented on July 23, 2024

nice hint @The-Compiler, unfortunately tokenize.detect_encoding isn't available in python2.7, presume pep257 aims support for python2.7

from pydocstyle.

peterjc avatar peterjc commented on July 23, 2024

I just traced a problem in my plugin based on pydocstyle to this bit of code:

https://github.com/PyCQA/pydocstyle/blob/2.0.0/src/pydocstyle/checker.py#L23

# If possible (python >= 3.2) use tokenize.open to open files, so PEP 263
# encoding markers are interpreted.
try:
    tokenize_open = tk.open
except AttributeError:
    tokenize_open = open

Would a backport of tokenize.open for Python 2 be acceptable here?

Note it seems that because later the contents of the file get executed, it is helpful to also remove/replace the encoding line to avoid triggering SyntaxError: encoding declaration in Unicode string when passing it to exec(...):

https://github.com/PyCQA/pydocstyle/blob/2.0.0/src/pydocstyle/parser.py#L286

        try:
            compile(src, filename, 'exec')
        except SyntaxError as error:
            six.raise_from(ParseError(), error)

I'm not proud of this hacked together back port, but it might serve if Python 2.7 support is desired:

peterjc/flake8-rst-docstrings@80697a6

from pydocstyle.

peterjc avatar peterjc commented on July 23, 2024

See also pull request #152 which added a test case using # -*- coding: Windows-1255 -*

from pydocstyle.

sigmavirus24 avatar sigmavirus24 commented on July 23, 2024

pycodestyle has code to work around the absence of tokenize.open. Flake8 has taken and improved it as well.

from pydocstyle.

peterjc avatar peterjc commented on July 23, 2024

@sigmavirus24 Can you point me at this code please? And can this issue be closed?

from pydocstyle.

aphedges avatar aphedges commented on July 23, 2024

pydocstyle has been using tokenizer.open when reading source files since 4948f22. This is therefore no longer a problem.

from pydocstyle.

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.