expand code style guide
This commit is contained in:
@@ -89,20 +89,23 @@ That is, use an assert if the following holds true: if the assert fails, it mean
|
|||||||
To check for user errors, such as application code using the wrong type when calling into the library, use Exceptions:
|
To check for user errors, such as application code using the wrong type when calling into the library, use Exceptions:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def publish(topic, *args, **kwargs):
|
import six
|
||||||
if type(topic) != unicode:
|
|
||||||
raise RuntimeError(u"URIs must be unicode - got {} instead".format(type(topic)))
|
def foo(uri):
|
||||||
|
if type(topic) != six.text_type:
|
||||||
|
raise RuntimeError(u"URIs for foo() must be unicode - got {} instead".format(type(uri)))
|
||||||
```
|
```
|
||||||
|
|
||||||
In this specific example, we also have a WAMP defined error:
|
In this specific example, we also have a WAMP defined error:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
import six
|
||||||
from autobahn.wamp import ApplicationError
|
from autobahn.wamp import ApplicationError
|
||||||
|
|
||||||
def publish(topic, *args, **kwargs):
|
def foo(uri):
|
||||||
if type(topic) != unicode:
|
if type(topic) != six.text_type:
|
||||||
raise ApplicationError(ApplicationError.INVALID_URI,
|
raise ApplicationError(ApplicationError.INVALID_URI,
|
||||||
"URIs must be unicode - got {} instead".format(type(topic)))
|
u"URIs for foo() must be unicode - got {} instead".format(type(uri)))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user