Mercurial > kallithea
annotate dev_requirements.txt @ 8163:24e1099e4f29
py3: make get_current_authuser handle missing tg context consistently and explicitly
tg context handling ends up using
tg.support.registry.StackedObjectProxy._current_obj for attribute access ...
which if no context has been pushed will end up in:
raise TypeError(
'No object (name: %s) has been registered for this '
'thread' % self.____name__)
utils2.get_current_authuser used code like:
if hasattr(tg.tmpl_context, 'authuser'):
Python 2 hasattr will call __getattr__ and return False if it throws any
exception. (It would thus catch the TypeError and silently fall through to use
the default user None.) This hasattr behavior is confusing and hard to use
correctly. Here, it was used incorrectly. It has been common practice to work
around by using something like:
getattr(x, y, None) is not None
Python 3 hasattr fixed this flaw and only catches AttributeError. The TypeError
would thus (rightfully) be propagated. That is a change that must be handled
when introducing py3 support.
The get_current_authuser code could more clearly and simple and py3-compatible
be written as:
return getattr(tmpl_context, 'authuser', None)
- but then we also have to handle the TypeError explicitly ... which we are
happy to do.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 31 Jan 2020 18:48:15 +0100 |
parents | 268c47a1a93d |
children | d122a9532630 |
rev | line source |
---|---|
7900
4dad662fe6fd
dev_requirements.txt: bump minimum pytest versions to a working set
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7810
diff
changeset
|
1 pytest >= 4.6.6, < 4.7 |
4dad662fe6fd
dev_requirements.txt: bump minimum pytest versions to a working set
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7810
diff
changeset
|
2 pytest-sugar >= 0.9.2, < 0.10 |
4dad662fe6fd
dev_requirements.txt: bump minimum pytest versions to a working set
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7810
diff
changeset
|
3 pytest-benchmark >= 3.2.2, < 3.3 |
4dad662fe6fd
dev_requirements.txt: bump minimum pytest versions to a working set
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
7810
diff
changeset
|
4 pytest-localserver >= 0.5.0, < 0.6 |
7929
8e0efe7b3b10
setup: set explicit minimum version for all dependencies
Mads Kiilerich <mads@kiilerich.com>
parents:
7900
diff
changeset
|
5 mock >= 3.0.0, < 3.1 |
8e0efe7b3b10
setup: set explicit minimum version for all dependencies
Mads Kiilerich <mads@kiilerich.com>
parents:
7900
diff
changeset
|
6 Sphinx >= 1.8.0, < 1.9 |
8137
268c47a1a93d
setup: bump webtest minimum version to 2.0.6 to get py3 stdlib support
Mads Kiilerich <mads@kiilerich.com>
parents:
7929
diff
changeset
|
7 WebTest >= 2.0.6, < 2.1 |
7810
5698307382de
scripts: introduce import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents:
7741
diff
changeset
|
8 isort == 4.3.21 |