Skip to content

Commit

Permalink
Merge pull request #53 from radaron/social/HSS-29595-upgrade-python-v…
Browse files Browse the repository at this point in the history
…ersion-in-richenum

Upgrade python version to support 3.9 and 3.10
  • Loading branch information
csizmaziakiki committed Jun 6, 2024
2 parents 9ed7e13 + 2d82c13 commit bbd530e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 51 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/python-version-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8"]
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +27,6 @@ jobs:
sudo apt install flake8
sudo apt install pylint
pip install pytest
pip install six
- name: Run Tests
run: |
flake8 tests src setup.py
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Developed and maintained by `Hearsay Social, Inc.
Contributors
============
| `Adam DePue <http://github.com/adepue>`_
| `Aron radics <http://github.com/radaron>`_
| `Akshay Shah <http://github.com/akshayjshah>`_
| `Dale Hui <http://github.com/dhui>`_
| `Robert MacCloy <http://github.com/rbm>`_
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ Changelog
1.0.0 (2013-08-16)
------------------
- Initial public release.

2.0.0 (2024-06-04)
------------------
- Remove six
- Remove python 3.7 support
- Add python 3.9 and 3.10 support
- Remove tox.ini
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
========
richenum
========
.. image:: https://circleci.com/gh/hearsaycorp/richenum/tree/master.svg?style=svg
.. image:: https://github.com/hearsaycorp/richenum/actions/workflows/python-version-tests.yml/badge.svg
:alt: Build Status
:target: https://circleci.com/gh/hearsaycorp/richenum/tree/master

.. image:: https://img.shields.io/pypi/v/richenum.svg
:alt: Latest PyPI Version
Expand All @@ -16,7 +15,7 @@ richenum
.. image:: https://img.shields.io/pypi/dm/richenum.svg
:alt: Pypi Downloads
:target: https://pypi.org/project/richenum/

=====
About
=====
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='richenum',
version='1.3.1',
version='2.0.0',
description='Enum library for python.',
long_description=(
open('README.rst').read() + '\n\n' +
Expand All @@ -16,8 +16,9 @@
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development :: Libraries :: Python Modules',
],
Expand All @@ -30,6 +31,5 @@
packages=find_packages('src'),
tests_require=['pytest'],
setup_requires=["pytest-runner"],
install_requires=['six'],
test_suite='tests'
)
36 changes: 10 additions & 26 deletions src/richenum/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
from functools import total_ordering
import logging
import numbers
from six import PY3
from six import string_types
from six import with_metaclass

from operator import itemgetter

if PY3:
unicode = str # workaround for flake8


logger = logging.getLogger(__name__)

Expand All @@ -34,15 +28,6 @@ class EnumLookupError(LookupError):
pass


def _str_or_ascii_replace(stringy):
if PY3:
return stringy
else:
if isinstance(stringy, str):
stringy = stringy.decode('utf-8')
return stringy.encode('ascii', 'replace')


def _items(dict):
try:
return dict.iteritems()
Expand Down Expand Up @@ -96,16 +81,15 @@ def __init__(self, canonical_name, display_name, *args, **kwargs):
def __repr__(self):
return "<%s: %s ('%s')>" % (
self.__class__.__name__,
_str_or_ascii_replace(self.canonical_name),
_str_or_ascii_replace(self.display_name),
self.canonical_name,
self.display_name,
)

def __unicode__(self):
return unicode(self.display_name)
return str(self.display_name)

def __str__(self):
return str(self.display_name) if PY3 else unicode(self).encode(
'utf-8', 'xmlcharrefreplace')
return str(self.display_name)

def __hash__(self):
return hash(self.canonical_name)
Expand Down Expand Up @@ -152,8 +136,8 @@ def __repr__(self):
return "<%s #%s: %s ('%s')>" % (
self.__class__.__name__,
self.index,
_str_or_ascii_replace(self.canonical_name),
_str_or_ascii_replace(self.display_name),
self.canonical_name,
self.display_name,
)

def __lt__(self, other):
Expand Down Expand Up @@ -225,7 +209,7 @@ def __contains__(cls, item):
members = cls.members()
if not members:
return False
if not type(members[0]) == type(item):
if not type(members[0]) is type(item):
return False
return (item in members)

Expand Down Expand Up @@ -279,7 +263,7 @@ def lookup(cls, field, value):
return member

if (
not isinstance(member_value, string_types) and
not isinstance(member_value, str) and
isinstance(member_value, collectionsAbc.Iterable) and
value in member_value
):
Expand Down Expand Up @@ -311,7 +295,7 @@ def choices(cls, value_field='canonical_name', display_field='display_name'):
return [m.choicify(value_field=value_field, display_field=display_field) for m in cls.members()]


class RichEnum(with_metaclass(_RichEnumMetaclass, _EnumMethods)):
class RichEnum(_EnumMethods, metaclass=_RichEnumMetaclass):
"""
Enumeration that can represent a name for referencing (canonical_name) and
a name for displaying (display_name).
Expand Down Expand Up @@ -339,7 +323,7 @@ class RichEnum(with_metaclass(_RichEnumMetaclass, _EnumMethods)):
__virtual__ = True


class OrderedRichEnum(with_metaclass(_OrderedRichEnumMetaclass, _EnumMethods)):
class OrderedRichEnum(_EnumMethods, metaclass=_OrderedRichEnumMetaclass):
"""
Use OrderedRichEnum when you need a RichEnum with index-based
access into the enum, e.g. OrderedRichEnumExample.from_index(0),
Expand Down
5 changes: 0 additions & 5 deletions tests/richenum/test_ordered_rich_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import unittest
import re
import pytest
from six import PY3
if PY3:
unicode = str # for flake8, mainly

from richenum import EnumConstructionException # noqa
from richenum import EnumLookupError # noqa
Expand Down Expand Up @@ -116,8 +113,6 @@ def test_unicode_handling(self):
exp = re.compile(r"<BreakfastEnumValue #3: oatmeal..? \('Oatmeal..?'\)>")
assert exp.search(repr(poop_oatmeal)) is not None
self.assertEqual(str(poop_oatmeal), "Oatmeal💩")
if not PY3:
self.assertEqual(unicode(poop_oatmeal), u"Oatmeal💩")

def test_enum_hashable(self):
self.assertTrue(hash(coffee))
5 changes: 0 additions & 5 deletions tests/richenum/test_rich_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import re
import unittest
import pytest
import six
if six.PY3:
unicode = str # for flake8, mainly

from richenum import EnumConstructionException # noqa
from richenum import EnumLookupError # noqa
Expand Down Expand Up @@ -142,8 +139,6 @@ def test_unicode_handling(self):
exp = re.compile(r"<VegetableEnumValue: okra..? \('Okra..?'\)>")
self.assertIsNotNone(exp.search(repr(poop_okra)))
self.assertEqual(str(poop_okra), "Okra💩")
if not six.PY3:
self.assertEqual(unicode(poop_okra), u"Okra💩")

def test_string_coercion(self):
class DisplayProxy():
Expand Down
7 changes: 0 additions & 7 deletions tox.ini

This file was deleted.

0 comments on commit bbd530e

Please sign in to comment.