From 7e5a83d42159bb0e9e0a3da1e5fdf5d8d71880ee Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 12 Feb 2019 14:37:08 -0600 Subject: [PATCH 1/4] Use parameter definition order for Python 3.6+ --- panel/param.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/panel/param.py b/panel/param.py index 8309c27b64..6886a7b399 100644 --- a/panel/param.py +++ b/panel/param.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, unicode_literals import os +import sys import json import types import inspect @@ -357,7 +358,9 @@ def _get_widgets(self): filtered = [(k,p) for (k,p) in sorted_precedence if ((p.precedence is None) or (p.precedence >= self.display_threshold))] groups = itertools.groupby(filtered, key=key_fn) - sorted_groups = [sorted(grp) for (k,grp) in groups] + # Params preserve definition order in Python 3.6+ + ordered_params = sys.version_info.major == 3 and sys.version_info.minor >= 6 + sorted_groups = [list(grp) if ordered_params else sorted(grp) for (k,grp) in groups] ordered_params = [el[0] for group in sorted_groups for el in group] # Format name specially From d4d784b9e801cff00ab401ce93fca65f250e3ea3 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 12 Feb 2019 15:32:17 -0600 Subject: [PATCH 2/4] Renamed sorted_groups to ordered_groups --- panel/param.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panel/param.py b/panel/param.py index 6886a7b399..79825caf5f 100644 --- a/panel/param.py +++ b/panel/param.py @@ -360,8 +360,8 @@ def _get_widgets(self): groups = itertools.groupby(filtered, key=key_fn) # Params preserve definition order in Python 3.6+ ordered_params = sys.version_info.major == 3 and sys.version_info.minor >= 6 - sorted_groups = [list(grp) if ordered_params else sorted(grp) for (k,grp) in groups] - ordered_params = [el[0] for group in sorted_groups for el in group] + ordered_groups = [list(grp) if ordered_params else sorted(grp) for (k,grp) in groups] + ordered_params = [el[0] for group in ordered_groups for el in group] # Format name specially ordered_params.pop(ordered_params.index('name')) From 791778df9554660124d9822571d7a5f7fa428220 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Wed, 13 Feb 2019 18:17:39 -0600 Subject: [PATCH 3/4] Fixed clashing variable name --- panel/param.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panel/param.py b/panel/param.py index 79825caf5f..b06e4acb08 100644 --- a/panel/param.py +++ b/panel/param.py @@ -359,8 +359,8 @@ def _get_widgets(self): if ((p.precedence is None) or (p.precedence >= self.display_threshold))] groups = itertools.groupby(filtered, key=key_fn) # Params preserve definition order in Python 3.6+ - ordered_params = sys.version_info.major == 3 and sys.version_info.minor >= 6 - ordered_groups = [list(grp) if ordered_params else sorted(grp) for (k,grp) in groups] + dict_ordered = sys.version_info.major == 3 and sys.version_info.minor >= 6 + ordered_groups = [list(grp) if dict_ordered else sorted(grp) for (k,grp) in groups] ordered_params = [el[0] for group in ordered_groups for el in group] # Format name specially From ec923e7363e98a1aa6a64ed15a7fcb4696976ae6 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Wed, 13 Feb 2019 18:19:52 -0600 Subject: [PATCH 4/4] Assuming dict ordering preserved for all future Python versions --- panel/param.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/panel/param.py b/panel/param.py index b06e4acb08..7404e846a6 100644 --- a/panel/param.py +++ b/panel/param.py @@ -359,7 +359,8 @@ def _get_widgets(self): if ((p.precedence is None) or (p.precedence >= self.display_threshold))] groups = itertools.groupby(filtered, key=key_fn) # Params preserve definition order in Python 3.6+ - dict_ordered = sys.version_info.major == 3 and sys.version_info.minor >= 6 + dict_ordered_py3 = (sys.version_info.major == 3 and sys.version_info.minor >= 6) + dict_ordered = dict_ordered_py3 or (sys.version_info.major > 3) ordered_groups = [list(grp) if dict_ordered else sorted(grp) for (k,grp) in groups] ordered_params = [el[0] for group in ordered_groups for el in group]