Skip to content

Commit

Permalink
Merge pull request #100 from hajgato/readme_update
Browse files Browse the repository at this point in the history
Add python3 recommendations to README.md HPC-7605
  • Loading branch information
wdpypere authored Mar 27, 2019
2 parents a0c3b01 + 5a0b5dd commit ee7b08d
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ class VscGroup(object):
=> do you need the import? use import as
did you mean to use the same name? ...

Redefined builtin
-----------------
use different name, for example change

```python
def filter(b_b):
"""Function filter"""
return b_b
```
=>
```python
def new_filter(b_b):
"""Function filter"""
return b_b
```

Fix Python 3 failing tests
==========================

* We try to follow https://docs.python.org/3/howto/pyporting.html
* some useful info can be found here as well https://portingguide.readthedocs.io/en/latest/index.html

unpacking-in-except / redefine-in-handler
-----------------------------------------

Expand All @@ -218,6 +240,128 @@ except (ExceptionOne, ExceptionTwo) ...

(espcially when used like `except A, B:` which should be `except (A, B):`.

Fixing print statement
----------------------

Use the oneliner:
```bash
find lib bin -name '*.py' | xargs futurize -w -f libfuturize.fixes.fix_print_with_import -n
```
Note: You need to install `python(2)-future` if you want to use `futurize` (or you have to have the `future` Python package).

Metaclass assignment
--------------------

```python
class Foo(Bar):

__metaclass__ = Baz
```
=>
```python
from future.utils import with_metaclass

class Foo(with_metaclass(Baz,Bar):
```

Old raise syntax
----------------
Python 2s **raise** statement was designed at a time when exceptions werent classes, and an exceptions _type_, _value_, and _traceback_ components were three separate objects. In Python 3, one single object includes all information about an exception.

```python
raise NameError, "Error"
```
=>
```python
raise NameError("Error")
```

or change
```python
raise NameError, "Error", some_traceback
```
=>
```python
raise NameError("Error")

e = NameError("Error")
e.__traceback__ = some_traceback
```

backtick
--------

```python
A = 2
B = `A`
```
=>
```python
A = 2
B = str(A)
```

Old ne operator
---------------

```python
if 2 <> 3:
```
=>
```python
if 2 != 3:
```

Octal literal
-------------

```python
os.chmod(foo, 0700)
```
=>
```python
os.chmod(foo, 0o700)
```

Import star module level
------------------------
Do not import \*, be more specific. If it is impossible, import it in the top level (and suppress the pyflakes error F403.)
```python
def coords(angle, distance):
"""Function coords"""
from math import *
return distance * cos(angle), distance * sin(angle)
```
=>
```python
from math import * # noqa: F403
def coords(angle, distance):
"""Function coords"""
return distance * cos(angle), distance * sin(angle)
```

Raising string
--------------
```python
raise ValueError, 'message'
```
=>
```python
raise ValueError('message')
```

Indexing exception
------------------
```python
except IndexError as err:
err[0]
```
=>
```python
except IndexError as err:
IndexError.args[0]
```

turning off these errors
-------------------------

Expand Down

0 comments on commit ee7b08d

Please sign in to comment.