Skip to content

Commit

Permalink
Added example file and extended example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Curry committed Apr 18, 2013
1 parent 771703b commit 12e296a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
22 changes: 18 additions & 4 deletions README.rst
Expand Up @@ -17,11 +17,11 @@ Installation

::

$ pip install py3kwarn
$ pip install py3kwarn

...or to install from the git repository::

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

Usage with vim
--------------
Expand All @@ -30,14 +30,28 @@ 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']
let g:syntastic_python_checkers=['flake8', 'py3kwarn']

Usage from the command line
---------------------------

::

$ py3kwarn [filename]
$ 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:14:1: PY3K (FixDict) d.keys() -> list(d.keys())
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:41:1: PY3K (FixFuture) from __future__ import absolute_import ->
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)

Testing
-------
Expand Down
77 changes: 77 additions & 0 deletions example.py
@@ -0,0 +1,77 @@
# FixApply
apply(hello, args, kwargs)

# FixBasestring
basestring

# FixBuffer
buffer('hello', 1, 3)

# FixCallable
callable('hello')

# FixDict
d.keys()
d.iteritems()
d.viewvalues()

# FixExcept
try:
import asdf
except E, T:
pass

# FixExec
exec code in ns1, ns2

# FixExecfile
execfile('test.py')

# FixFilter
filter(lambda x: x, [1, 2, 3])

# FixFuncattrs
def test():
pass
test.func_name
test.func_closure
test.func_dict

# FixFuture
from __future__ import absolute_import

# FixHasKey
d.has_key('foobar')

# FixImport
from py3kwarn import tests

# FixImports
import StringIO
import cStringIO
import cPickle
import __builtin__

# FixInput
input('FixInput')

# FixIntern
intern(s)

# FixIsinstance
isinstance(x, (int, long))
isinstance(x, (int, int))

# FixItertoolsImports
from itertools import imap
from itertools import ifilter
from itertools import izip
from itertools import ifilterfalse

# FixUnicode
u'Hello World'

# FixLong
long

# More...
7 changes: 5 additions & 2 deletions py3kwarn/run.py
Expand Up @@ -129,5 +129,8 @@ def warnings_for_files(filenames):

def main():
import sys
for warning in warnings_for_files([sys.argv[1], ]):
print(warning[1])
if sys.version_info >= (3, 0):
print("py3kwarn requires Python 2.6 or 2.7")
else:
for warning in warnings_for_files([sys.argv[1], ]):
print(warning[1])

0 comments on commit 12e296a

Please sign in to comment.