Skip to main content
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: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:36:1: PY3K (FixFuncattrs) test.func_name; -> test.__name__;
example.py:37:1: PY3K (FixFuncattrs) test.func_closure; -> test.__closure__;
example.py:38:1: PY3K (FixFuncattrs) test.func_dict; -> test.__dict__;
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:66:1: PY3K (FixItertoolsImports) from itertools import imap ->
example.py:67:1: PY3K (FixItertoolsImports) from itertools import ifilter; ->
example.py:68:1: PY3K (FixItertoolsImports) from itertools import izip; ->
example.py:69:1: PY3K (FixItertoolsImports) from itertools import ifilterfalse; -> from itertools import filterfalse;
example.py:62:1: PY3K (FixLong) long; -> int;
example.py:75:1: PY3K (FixLong) long -> int
example.py:50:1: PY3K (FixImports) import StringIO -> import io
example.py:51:1: PY3K (FixImports) import cStringIO; -> import io;
example.py:52:1: PY3K (FixImports) import cPickle; -> import pickle;
example.py:53:1: PY3K (FixImports) import __builtin__; -> import builtins;
example.py:62:1: PY3K (FixIsinstance) isinstance(x, (int, int)) -> isinstance(x, int)
example.py:63:1: PY3K (FixIsinstance) isinstance(x, (int, int)); -> isinstance(x, int);
example.py:11:1: PY3K (FixCallable) callable('hello') -> isinstance('hello', collections.Callable)
example.py:59:1: PY3K (FixIntern) intern(s) -> sys.intern(s)

Modifying code automatically

Problems can be fixed via py3kwarn2to3:

$ py3kwarn2to3 --write example.py

Testing

Testing can be done with make test. py3kwarn also supports tox. 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.

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

Metadata

Release files for py3kwarn 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py3kwarn 0.4.2
File Size Uploaded
py3kwarn-0.4.2.tar.gz 93.1 kB Details

Release files / py3kwarn-0.4.2.tar.gz

Download URL py3kwarn-0.4.2.tar.gz
Size 93.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5444f1930bfe87b541962879f5d6eb03d47417ce599a8ce5225ee7d75860a364
BLAKE2b-256 checksum
How to use checksums
466b7900ffc354eef586eb2f90e6188a39da6f14ada176c9764725d78e2d01a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.4.4

1 release file

0.4.3

1 release file

This release

0.4.2 This release

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2.3

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page