Skip to content

Commit

Permalink
Use parameter definition order for Python 3.6+ (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens authored and philippjfr committed Feb 14, 2019
1 parent e7cf530 commit 122093a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import, division, unicode_literals

import os
import sys
import json
import types
import inspect
Expand Down Expand Up @@ -357,8 +358,11 @@ 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]
ordered_params = [el[0] for group in sorted_groups for el in group]
# Params preserve definition order in Python 3.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]

# Format name specially
ordered_params.pop(ordered_params.index('name'))
Expand Down

0 comments on commit 122093a

Please sign in to comment.