Skip to main content

A small wrapper around lib2to3 to help write Python 3 compatible code.

Project description

Build status Test coverage status

py3kwarn is a small wrapper around lib2to3 to help write Python3 compatible code. It provides flake8-style warning messages.

See also:

Pull requests are welcome!

Installation

Supports Python 2.6, 2.7, and 3.3+

$ pip install py3kwarn

…or to install from the git repository:

$ pip install -e git+git://github.com/liamcurry/py3kwarn.git#egg=py3kwarn

Usage with vim

You can use py3kwarn with syntastic. If you want to use py3kwarn with another syntax checker (like flake8), then you will have to add this to your vim config:

let g:syntastic_python_checkers=['flake8', 'py3kwarn']

Usage from the command line

$ py3kwarn example.py
example.py:2:1: PY3K (FixApply) apply(hello, args, kwargs) -> hello(*args, **kwargs)
example.py:5:1: PY3K (FixBasestring) basestring -> str
example.py:11:1: PY3K (FixCallable) callable('hello') -> isinstance('hello', collections.Callable)
example.py:15:1: PY3K (FixDict) d.iteritems(); -> iter(d.items());
example.py:16:1: PY3K (FixDict) d.viewvalues(); -> d.values();
example.py:19:1: PY3K (FixExcept) try:import asdf;except E, T:pass; -> try:import asdf;except E as T:pass;
example.py:25:1: PY3K (FixExec) exec code in ns1, ns2; -> exec(code, ns1, ns2);
example.py:28:1: PY3K (FixExecfile) execfile('test.py') -> exec(compile(open('test.py').read(), 'test.py', 'exec'))
example.py:31:1: PY3K (FixFilter) filter(lambda x: x, [1, 2, 3]) -> [x for x in [1, 2, 3] if x]
example.py:44:1: PY3K (FixHasKey) d.has_key('foobar') -> 'foobar' in d
example.py:56:1: PY3K (FixInput) input('FixInput') -> eval(input('FixInput'))
example.py:59:1: PY3K (FixIntern) intern(s) -> sys.intern(s)
example.py:66:1: PY3K (FixItertoolsImports) from itertools import ->
example.py:67:1: PY3K (FixItertoolsImports) from itertools import; ->
example.py:68:1: PY3K (FixItertoolsImports) from itertools import; ->
example.py:72:1: PY3K (FixUnicode) u'Hello World' -> 'Hello World'

Testing

Testing can be done with make test. py3kwarn also supports tox, which assumes pythonbrew is installed. This enables quickly testing changes in many versions of python. Take a look at the tox.ini file for more details.

Contributing

To contribute, fork the repo and clone to your local machine.

Create a virtual environment and

pip install -r requirements_dev.txt

Then just make a pull request with the issues you’ve fixed!

TODO

  • Friendlier messages.

  • A flake8 extension.

  • Use argparse to add smarter options.

  • Flags to ignore certain errors

  • Compatibility mode, where warning messages provide suggestions to write forwards compatible code. Make this the default.

  • Make it faster. Right now it is quite slow compared to other syntax checkers. Major refactoring may be necessary.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py3kwarn-0.4.tar.gz (92.2 kB view details)

Uploaded Source

File details

Details for the file py3kwarn-0.4.tar.gz.

File metadata

  • Download URL: py3kwarn-0.4.tar.gz
  • Upload date:
  • Size: 92.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py3kwarn-0.4.tar.gz
Algorithm Hash digest
SHA256 c418abfe7a01049de313235112ba86f2aae6c014e39d6875146f7c44673ee8e6
MD5 4f5992ac2bb2392986b6cf91326f41c5
BLAKE2b-256 a9ef1d90f60791b3494b45a52052739df936ca42bfab7cf2d81bcaa3cbfaad15

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page