| 14 | |
| 15 | What to consider: |
| 16 | |
| 17 | * The API is used not only by the GRASS Development Team (core devs) but in general, e.g. by writing addons or custom user scripts. |
| 18 | * Maybe the core devs can be convinced to follow certain special practices for the core modules, but it doesn't seem realistic that addon contributors will follow them if there are too distant from what is standard for the language (less serious example is requiring PEP8 conventions versus some custom ones). |
| 19 | * The purpose of the API is to make it simple for people to use and extend GRASS GIS. |
| 20 | * Trained (and even the non-trained) Python 3 programmers will expect API to behave in the same way as the standard library and language in general. |
| 21 | * One writes `os.environ['PATH']`, not `os.environ[b'PATH']` nor `os.environ[u'PATH']`. |
| 22 | * GUI needs Unicode at the end. |
| 23 | |
| 48 | |
| 49 | Unicode as the default type in the API, e.g. for keys, but also for many values, is supported by Unicode being the default string literal type in Python 3. API users will expect that expressions such as hypothetical `computation_region['north']` will work. Unlike in Python 2, there is a difference in Python 3 between `computation_region[u'north']` and `computation_region[b'north']`. See comparison of dictionary behavior in 2 and 3: |
| 50 | |
| 51 | {{{ |
| 52 | #!python |
| 53 | # Python 2 |
| 54 | >>> d = {'a': 1, b'b': 2} |
| 55 | >>> d['b'] |
| 56 | 2 |
| 57 | >>> d[u'b'] |
| 58 | 2 |
| 59 | >>> # i.e. no difference between u'' and b'' keys |
| 60 | >>> and that applies for creating also: |
| 61 | >>> d = {u'a': 1, b'a': 2} |
| 62 | >>> d['a'] |
| 63 | 2 |
| 64 | >>> # because |
| 65 | >>> d |
| 66 | {u'a': 2} |
| 67 | # Python 3 |
| 68 | >>> # unlike in 2, we get now two entries: |
| 69 | >>> d = {'a': 1, b'a': 2} |
| 70 | >>> d |
| 71 | {b'a': 2, 'a': 1} |
| 72 | >>> d['a'] |
| 73 | 1 |
| 74 | >>> d[b'a'] |
| 75 | 2 |
| 76 | >>> # it becomes little confusing when we combine unicode and byte keys |
| 77 | >>> d = {'a': 1, b'b': 2} |
| 78 | >>> d['a'] |
| 79 | 1 |
| 80 | >>> d['b'] |
| 81 | Traceback (most recent call last): |
| 82 | File "<stdin>", line 1, in <module> |
| 83 | KeyError: 'b' |
| 84 | >>> d[b'b'] |
| 85 | 2 |
| 86 | >>> # in other words, user needs to know and specify the key as bytes |
| 87 | }}} |