Giter Site home page Giter Site logo

nocaselist's Introduction

nocaselist - A case-insensitive list for Python

Version on Pypi Test status (master) Docs status (master) Test coverage (master)

Overview

Class NocaseList is a case-insensitive list that preserves the lexical case of its items.

Example:

$ python
>>> from nocaselist import NocaseList

>>> list1 = NocaseList(['Alpha', 'Beta'])

>>> print(list1)  # Any access is case-preserving
['Alpha', 'Beta']

>>> 'ALPHA' in list1  # Any lookup or comparison is case-insensitive
True

The NocaseList class supports the functionality of the built-in list class of Python 3.8 on all Python versions it supports (except for being case-insensitive, of course).

The case-insensitivity is achieved by matching any key values as their casefolded values. By default, the casefolding is performed with str.casefold() for unicode string keys and with bytes.lower() for byte string keys. The default casefolding can be overridden with a user-defined casefold method.

Installation

To install the latest released version of the nocaselist package into your active Python environment:

$ pip install nocaselist

The nocaselist package has no prerequisite Python packages.

For more details and alternative ways to install, see Installation.

Documentation

Change History

Contributing

For information on how to contribute to the nocaselist project, see Contributing.

License

The nocaselist project is provided under the Apache Software License 2.0.

nocaselist's People

Contributors

andy-maier avatar

Stargazers

 avatar

Watchers

 avatar  avatar

nocaselist's Issues

Test with latest package levels does not use latest indirect dependents

Actual behavior

The installation of packages is done with pip install --upgrade. That does not upgrade already installed versions of indirect dependents. The Ubuntu used by Travis has quite a number of packages preinstalled in the virtualenv it provides, so these packages stay at versions that are not the latest, if they satisfy the minimum requirements of the other packages.

Expected behavior

Testing with latest package levels should upgrade all packages including indirect dependencies.

This can be achieved by adding the pip option --upgrade-strategy eager.

Execution environment

  • nocaselist version: 1.0.3
  • Python version: any
  • Operating System (type+version): any

installtest fails on pypy3 with latest package levels

From Travis run on pypy3 with latest package levels (see https://travis-ci.org/github/pywbem/nocaselist/jobs/709856857):

$ make installtest
Makefile: Running install tests
tests/installtest/test_install.sh dist/nocaselist-1.0.0.dev1-py2.py3-none-any.whl dist/nocaselist-1.0.0.dev1.tar.gz python
Preparing for the tests
Creating test directory: tests/installtest/../../tmp_installtest
Creating source archive unpack directory: tests/installtest/../../tmp_installtest/src_dist
Removing .egg file: tests/installtest/../../dist/nocaselist*.egg
Testcase test1: Pip install from repo root directory: tests/installtest/../..
Saving location of current virtualenv: /home/travis/virtualenv/pypy3.6-7.1.1
Before creating virtualenv: tests/installtest/../../tmp_installtest/virtualenvs/nocaselist_test_test1
Python version: Python 3.6.1 (784b254d6699, Apr 14 2019, 10:22:42)
[PyPy 7.1.1-beta0 with GCC 6.2.0 20160901] from /home/travis/virtualenv/pypy3.6-7.1.1/bin/python
Pip version: pip 20.1.1 from /home/travis/virtualenv/pypy3.6-7.1.1/site-packages/pip (python 3.6)
Creating virtualenv: tests/installtest/../../tmp_installtest/virtualenvs/nocaselist_test_test1
Activating virtualenv: tests/installtest/../../tmp_installtest/virtualenvs/nocaselist_test_test1
Error: Command failed with rc=1: source tests/installtest/../../tmp_installtest/virtualenvs/nocaselist_test_test1/bin/activate, output follows:
tests/installtest/test_install.sh: line 230: tests/installtest/../../tmp_installtest/virtualenvs/nocaselist_test_test1/bin/activate: No such file or directory
Makefile:573: recipe for target 'installtest' failed
make: *** [installtest] Error 1
The command "make installtest" exited with 2.

Run coveralls on all Python versions

Coveralls is able to merge the results of multiple runs on different Python versions. Remove the restriction in .travis.yml to invoke it only on a single Python version.

Remove Python version enforcement

The __init__.py module enforces the supported Python versions at run time. For a package like nocaselist, this seems overkill. Remove the enforcement.

Support clear() also on Python 2

The built-in list class supports clear() only starting with Python 3.3.

I think it would be good for ease of use if NocaseList supported all features from Python 3.8 back on all supported Python versions. I think the clear() method is the only one that would need to be added on Python 2.

Non-standard behavior for `+` and `+=`

The implementations of + and += in NocaseList behave different from the built-in list.

  • For +, the built-in list treats the right hand operand as an iterable of items to be added and requires it to be a list, while NocaseList treats the the right hand operand as a single item to add (tested on Python 2.7 and 3.8):
>>> r = list() + 'Dog'; r
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
>>> r = NocaseList() + 'Dog'; r
['Dog']

>>> r = list() + ['Dog']; r
['Dog']
>>> r = NocaseList() + ['Dog']; r
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/maiera/PycharmProjects/pywbem/nocaselist/nocaselist/_nocaselist.py", line 116, in __add__
    lst.append(value)
  File "/Users/maiera/PycharmProjects/pywbem/nocaselist/nocaselist/_nocaselist.py", line 319, in append
    self._lc_list.append(value.lower())
AttributeError: 'list' object has no attribute 'lower'
  • For +=, the built-in list treats the right hand operand as an iterable of items to be added (but does not require it to be a list), while NocaseList treats the the right hand operand as a single item to add (tested on Python 2.7 and 3.8):
>>> r = list(); r += 'Dog'; r
['D', 'o', 'g']
>>> r = NocaseList(); r += 'Dog'; r
['Dog']

>>> r = list(); r += ['Dog']; r
['Dog']
>>> r = NocaseList(); r += ['Dog']; 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/maiera/PycharmProjects/pywbem/nocaselist/nocaselist/_nocaselist.py", line 127, in __iadd__
    self.append(value)
  File "/Users/maiera/PycharmProjects/pywbem/nocaselist/nocaselist/_nocaselist.py", line 319, in append
    self._lc_list.append(value.lower())
AttributeError: 'list' object has no attribute 'lower'

The test cases were:

from nocaselist import NocaseList

r = list() + 'Dog'; r
r = NocaseList() + 'Dog'; r

r = list() + ['Dog']; r
r = NocaseList() + ['Dog']; r

r = list(); r += 'Dog'; r
r = NocaseList(); r += 'Dog'; r

r = list(); r += ['Dog']; r
r = NocaseList(); r += ['Dog']; r

r = list(); r.extend('Dog'); r
r = NocaseList(); r.extend('Dog'); r

r = list(); r.extend(['Dog']); r
r = NocaseList(); r.extend(['Dog']); r

r = list(); r.append('Dog'); r
r = NocaseList(); r.append('Dog'); r

r = list(); r.append(['Dog']); r
r = NocaseList(); r.append(['Dog']); r

Version incompatibilities during make develop

After cleaning up the dependencies in PR #8, the following incompatibilities are still reported:

Locally on macOS using Python 2.7 + 3.8 with latest package levels:

ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.

Python 2.7 with latest package levels (see Travis run):

ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.
ERROR: tox 3.17.1 has requirement six>=1.14.0, but you'll have six 1.11.0 which is incompatible.
ERROR: virtualenv 20.0.27 has requirement pathlib2<3,>=2.3.3; python_version < "3.4" and sys_platform != "win32", but you'll have pathlib2 2.3.2 which is incompatible.

Python 3.4 with latest package levels (see Travis run):

ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.
ERROR: tox 3.14.0 has requirement importlib-metadata<1,>=0.12; python_version < "3.8", but you'll have importlib-metadata 1.1.3 which is incompatible.

Python 3.5 + 3.8 + pypy(2.7) + pypy3(3.6) with latest package levels (see Travis run + Travis run + Travis run + Travis run):

ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.
ERROR: tox 3.17.1 has requirement six>=1.14.0, but you'll have six 1.12.0 which is incompatible.

Python 3.6 + 3.7 with latest package levels (see Travis run + Travis run):

ERROR: astroid 2.4.2 has requirement six~=1.12, but you'll have six 1.11.0 which is incompatible.
ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.
ERROR: tox 3.17.1 has requirement six>=1.14.0, but you'll have six 1.11.0 which is incompatible.

Python 2+3 on macOS with latest package levels (see Travis run + Travis run):

ERROR: flake8 3.8.3 has requirement pyflakes<2.3.0,>=2.2.0, but you'll have pyflakes 2.1.1 which is incompatible.

Resolve issues with Fedora packaging

The Fedora packaging request https://bugzilla.redhat.com/show_bug.cgi?id=1880953 has a comment with some suggestions:

  • Please bump to 1.0.3
  • Files are 404, relying on https://github.com/pywbem/nocaselist/blob/master/packaging/fedora/python-nocaselist.spec
  • You don't need to specify the BuildRequires twice:
    BuildRequires:  python3-devel
    BuildRequires:  python3dist(setuptools)
    
    # Test deps
    BuildRequires:  python3dist(pytest)
    BuildRequires:  python3dist(six)
    
    and here:
    %package -n python3-%{srcname}
    Summary:        %{summary}
    BuildRequires:  python3-devel
    BuildRequires:  python3dist(setuptools)
    # Test deps
    BuildRequires:  python3dist(pytest)
    BuildRequires:  python3dist(six)
    

AttributeError: 'Path' object has no attribute 'write_bytes' from virtualenv on py34

Actual behavior

See Travis run: https://travis-ci.org/github/pywbem/nocaselist/jobs/732737366

Testcase test1: Pip install from repo root directory: /home/travis/build/pywbem/nocaselist
Saving location of current virtualenv: /home/travis/virtualenv/python3.4.8
Before creating virtualenv: /home/travis/build/pywbem/nocaselist/tmp_installtest/virtualenvs/nocaselist_test_test1
Python version: Python 3.4.8 from /home/travis/virtualenv/python3.4.8/bin/python
Pip version: pip 19.1.1 from /home/travis/virtualenv/python3.4.8/lib/python3.4/site-packages/pip (python 3.4)
Creating virtualenv: /home/travis/build/pywbem/nocaselist/tmp_installtest/virtualenvs/nocaselist_test_test1
Error: Command failed with rc=1: virtualenv -p /home/travis/virtualenv/python3.4.8/bin/python  /home/travis/build/pywbem/nocaselist/tmp_installtest/virtualenvs/nocaselist_test_test1, output follows:
AttributeError: 'Path' object has no attribute 'write_bytes'
Makefile:585: recipe for target 'installtest' failed

Expected behavior

Success

Execution environment

  • nocaselist version: 1.0.2
  • Python version: 3.4
  • Operating System (type+version): Ubuntu (Travis)

Switch to sphinx-rtd-theme

The Python classic theme is really outdated these days, with Python 2.7 being EOL. Switch to using the sphinx_rtd_theme (see nocasedict).

AttributeError: 'NocaseList' object has no attribute '_lc_list' during unpickling

Actual behavior

When pickling an object of NocaseList, the following error shows up during unpickling:

>>> ncl = NocaseList(['a', 'B'])
>>> pkl = pickle.dumps(ncl)
>>> ncl2 = pickle.loads(pkl)
AttributeError: 'NocaseList' object has no attribute '_lc_list'

Expected behavior

Should work.

Execution environment

  • nocaselist version: 1.0.1
  • Python version: 3.8.5
  • Operating System (type+version): MacOS

Remove typing-extensions dependency for Python >=3.10

The features imported from typing-extensions are:

try:
    from typing import SupportsIndex  # type: ignore
except ImportError:
    from typing_extensions import SupportsIndex  # Python <=3.7

try:
    from typing import TypeAlias  # type: ignore
except ImportError:
    from typing_extensions import TypeAlias  # Python <=3.9

This means starting with Python 3.10, these features are integrated into the Python typing module, and the typing-extensions package is not needed.

However, the dependency on the typing-extensions package is defined for all Python versions:

# On Python 3.6, pip 21.3.1 is the newest version and it fails recognizing
#   that typing-extensions 4.2.0 started requiring Python>=3.7
typing-extensions>=3.10,<4.2.0; python_version == '3.6'
typing-extensions>=3.10; python_version >= '3.7'

This issue is to remove the dependency to the typing-extensions package for Python >=3.10.

Testcases that specify no expected warning tolerate warnings

Actual behavior

Testcases that specify no expected warning tolerate warnings that occur nevertheless.

Expected behavior

Testcases that specify no expected warning should verify that no warning occurs and fail otherwise.

Execution environment

  • nocasedict version: 1.0.2
  • Python version: and
  • Operating System (type+version): any

Add comment why __sizeof__() is not implemented

The sys.getsizeof(obj) function returns the memory size of obj in Bytes. It does that by calling __sizeof__() on the object and adding the GC overhead if the object is GC-managed.

The rules for whether a user-defined class like NocaseList has to implement __sizeof__() are not documented in the Python docs.

Here is a comparison between list and NocaseList that shows reaonable sizes for NocaseList.

Therefore, all that seems to be needed is to add a comment as to why sizeof() is not implemented.

import sys
from nocaselist import NocaseList
nl = NocaseList()
sl = list()
print("len list NocaseList")
for x in range(0, 25):
    print(x, sys.getsizeof(sl), sys.getsizeof(nl))
    value = str(x)
    nl.append(value)
    sl.append(value)

resulting in:

len list NocaseList
0 56 72
1 88 104
2 88 104
3 88 104
4 88 104
5 120 136
6 120 136
7 120 136
8 120 136
9 184 200
10 184 200
11 184 200
12 184 200
13 184 200
14 184 200
15 184 200
16 184 200
17 256 272
18 256 272
19 256 272
20 256 272
21 256 272
22 256 272
23 256 272
24 256 272

2.0.0: pytest is falang in all units with `TypeError: exceptions must be derived from Warning, not <class 'NoneType'>`

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using installer module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")

Looks like it may be cause by use latest pytest 8.1.1 but I'm not 100% sure.

Optimize pip backtracking in "make develop"

"make develop" causes pip to use backtracking back to:

Using cached tox-4.0.1-py3-none-any.whl.metadata (4.9 kB)
Using cached sphinx-6.0.0-py3-none-any.whl.metadata (6.2 kB)
Using cached pyproject_api-1.5.1-py3-none-any.whl.metadata (2.6 kB)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.