Commit Graph

154 Commits

Author SHA1 Message Date
Joshua Bronson f48bf580dc Update dev deps, use tox-uv
Also use a new --hypothesis-profile=less-examples by default.

Finally, remove --benchmark-* options from pytest.ini (which disabled
pytest-benchmark anyway) so that pytest-benchmark need not be installed
only to avoid an error that the --benchmark-disable option is
unrecognized.
2024-03-15 20:54:43 -04:00
Joshua Bronson 0cb7d99aed Minor changes to hypothesis tests.
Use sampled_from(powerset(keys_cross_vals)) for items strategy (and so
forth) to avoid hypothesis generating invalid examples.
2024-02-25 15:33:14 -05:00
Joshua Bronson 886187aa89 Minor improvements to hypothesis tests. 2024-02-18 13:58:28 -05:00
Joshua Bronson 0761d217ce Drop use of `typing.TypeAlias` in type hints (fix #310).
`typing.TypeAlias` was added in Python 3.10. In Python <= 3.9, using
`typing.TypeAlias` as a type hint confuses mypy.

To avoid this, either `typing_extensions.TypeAlias` must be used, or the
`TypeAlias` type hint may be dropped entirely in favor of relying on
type inference. Based on the current, limited usage of `TypeAlias`,
the latter is preferable.

Run mypy as part of automated tests for every supported Python version
to catch such issues in the future.
2024-02-18 12:18:28 -05:00
Joshua Bronson 709649526d Add a new 'benchmark' workflow
...that uses a new cachegrind runner to exercise
tests/microbenchmarks.py in CI and compare against baseline benchmark
results. A run will fail if any benchmark slows down by 10% or more. Add
a 'benchmark' tox environment to facilitate running benchmarks locally.

Also remove use of `@override` to improve performance, and include some
other minor code improvements.
2024-01-25 15:45:48 -05:00
Joshua Bronson 734622bda8 Various improvements.
- Use positional-only syntax rather than typing.overload's for various
  methods now that 3.7 is no longer supported. This works around
  mypyc/mypyc#961 but is also preferable on its own merits.

- Other minor changes to enable `mypyc _base.py` to successfully
  compile, such as not assuming `BidictBase.__dict__`.

- Use `typing.override` on 3.12.

- Prefer `alias = t.Tuple[...]` over `alias = 'tuple[...]'`, because
  this will allow ruff's pyupgrade rules to automatically rewrite these
  to `alias = tuple[...]` once we drop support for 3.8.

- Other minor code, docs, and test improvements.

CI:

- Enable coverage for 3.11 now that we use typing.override on 3.12+ and
  use a dummy impl on <3.12.

- Increase max-examples for the "more-examples" hypothesis profile to 999.
  With max-examples=500, the latest scheduled test run on GitHub Actions
  took under 5 minutes, so we can afford to increase this a lot more.

- Use the "more-examples" profile for all jobs in the test matrix for
  scheduled test runs, since we can afford it.
2024-01-12 17:15:15 -05:00
Joshua Bronson c64ae08b18 Happy 2024 2024-01-09 13:38:23 -05:00
Joshua Bronson 1b92df40e5 rm OnDup.kv 2024-01-09 13:23:48 -05:00
Joshua Bronson 678c007d39
bugfix + rewrite tests + misc. improvements (#295)
- Fix `bidict(None)` bug (should raise TypeError).

- Simplify hypothesis tests, especially by using stateful testing.

- Add overriding type hints for `inv` for each bidict type
  (not just for `inverse`).

- Improve docs and fix readthedocs build as of move to python3.12 for
  building docs.
2024-01-08 20:56:05 -05:00
Joshua Bronson 869f7c2fb0 rm out-of-date test code+comments, minor improvements 2023-12-26 16:44:46 -05:00
Joshua Bronson f9a47770e6 Drop FrozenOrderedBidict
...now that Python 3.7 is no longer supported.

frozenbidict now provides everything that FrozenOrderedBidict provided
(including reversibility) on all supported Python versions, with less
space overhead.

Closes #290.

Also prune very old release notes from the CHANGELOG.
2023-10-13 18:05:16 -04:00
Joshua Bronson 68858ec42b Drop namedbidict.
Searching all of GitHub reveals very low usage, and users are better off
just making an instance of an out-of-the-box bidict type and giving it
a good name, as in `element_by_symbol = bidict.bidict({"C": "carbon"})`.
2023-10-08 12:42:20 -04:00
Joshua Bronson f4823c78f3 Minor improvements to code and type hints.
Most notably, __init__, update(), and related methods now handle
SupportsKeysAndGetItem objects that are not mappings the same way that
collections.abc.MutableMapping.update() does.

Also apply changes from pyupgrade.
2023-10-08 12:31:30 -04:00
Joshua Bronson 8abe99e0e1 Enable more ruff rules + black auto-formatting. (#286) 2023-09-10 15:22:07 -04:00
Vasista Vovveti 3ded9f2ea5 Fix type hint for test_frozenbidicts_hashable 2023-07-22 11:00:59 -04:00
Joshua Bronson d9ccaa7918 Upgrade dev dependencies, drop support for Python 3.7.
Python 3.7 reached end of life on 2023-06-27 and is no longer supported
by all of bidict's development dependencies (e.g. hypothesis).
No longer advertise support for 3.7 in the project metadata, and remove
3.7 from the tox test matrix and in CI.

Also switch to using separate requirements files per Python version,
which allows pinning to dependencies' hashes.

Finally, don't bother adding dynamic optional-dependencies to
pyproject.toml, it's causing problems with lockfiles that use hashes.
2023-07-05 20:16:40 -04:00
Joshua Bronson 9b791c4b39 Improve some type hints.
Closes #278.
2023-06-17 11:32:01 -04:00
Joshua Bronson 0738708077 Test with python3.12 (beta) 2023-06-17 11:30:27 -04:00
Joshua Bronson 6c27412ad9 Go back to pytest-sphinx, use pytest-clarity, update deps
* Use pytest-sphinx to have pytest run doctests in Sphinx docs rather
  than using Sphinx to run these via run_tests.py.

  * Sphinx is no longer a test dependency, which allows upgrading to
    Sphinx 6.0 while still being able to run the tests with Python 3.7.
    (Sphinx 6.0 dropped support for 3.7.)

  * Use conftest.py rather than testsetup or doctest_global_setup, which
    pytest-sphinx does not currently support.

  * Don't use :skipif: in doctest:: directives since pytest-sphinx does
    not currently support it (thisch/pytest-sphinx#9). Instead just
    don't ever run the one doctest that was using this, since the
    behavior it was testing is also covered by several tests in
    test_properties.py that do still properly get run conditionally
    (specifically, the "freed on zero refcount" tests are still run on
    CPython but not PyPy).

  * Don't use >>> for code we don't want to test, since pytest-sphinx
    will otherwise still run it even if it's in a code-block directive
    (and sprinkling `# doctest: SKIP` everywhere as an alternative is
    noisy).

* Add pytest-clarity to dev dependencies and pass -vv to pytest by
  default to enable pytest-clarity's nicer diffs in development.
2023-01-04 00:52:12 -05:00
Joshua Bronson b0d602ea06 Happy 2023 + bump version post-release 2022-12-31 20:58:02 -05:00
Joshua Bronson da526c4c45 Type check tests, fix inverted type hint, prepare for 0.22.1 release
* Add type hints to tests and no longer exclude them from type checking.

* Fix the return type hint of bidict.inverted() to return an Iterator
  (aliased as ItemsIter), not an Iterable.

* Rename the internal type alias for Iterable[Tuple[KT, VT]] from
  IterItems to Items, and likewise MapOrIterItems to MapOrItems.
2022-12-31 20:52:38 -05:00
Joshua Bronson aebc3d08f5 rm defunct pylint references 2022-12-29 15:46:23 -05:00
Joshua Bronson 689fe19201 Daily CI job with --hypothesis-profile=more-examples
Enabled for Python 3.10, since coverage is enabled for 3.11,
which already slows down the tests enough.

Also, rm unused HYPOTHESIS_GEN_MAX_SIZE logic.
2022-12-29 11:12:53 -05:00
Joshua Bronson 79baf860b7 Use pyproject.toml instead of setup.py, etc.
* Ditch setup.py in favor of setuptools' PEP 621 support. Ref:
  https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

* Declare development dependencies in pyproject.toml rather than
  requirements/*.in

* Ditch pip-compile-multi which does not support sourcing deps from pyproject.toml

* Compile dependencies into dev-deps/*.txt rather than requirements/*.txt

* Don't include development-related files in the sdist or wheel.

* Drop less important bidict.metadata attributes
  (__maintainer__, __email__, __status__, __keywords__, __project_urls__)
  and make __author__ a dictionary with "name" and "email" keys
  to match the standard format in pyproject.toml.
2022-12-04 21:20:15 -05:00
Joshua Bronson 333e2e19d3 Upgrade dev dependencies. 2022-06-01 11:13:47 -04:00
Joshua Bronson cb2fcda454 Upgrade dev dependencies. 2022-03-27 16:36:17 -04:00
Joshua Bronson 2bee83b0d6 OrderedBidict pickling + minor code improvements
- Ensure that (un)pickling OrderedBidicts is order-preserving.
- Refactor __reduce__, _reduce_factory, and _init_from
  to use new private constructor _from_other.
- NamedBidictBase and GeneratedBidictInverse marker classes
  don't need to derive from BidictBase.
2022-02-16 10:38:37 -05:00
Joshua Bronson b5c9f346ce (c) 2022-02-15 15:37:25 -05:00
Joshua Bronson a239aa7917 Minor refactor. 2022-02-13 11:49:12 -05:00
Joshua Bronson 4f12c7f9eb Refine proxy logic for _OrderedBidictKeysView and _OrderedBidictItemsView 2022-02-12 14:59:03 -05:00
Joshua Bronson 5504a54bba Minor updates. 2022-02-11 16:59:06 -05:00
Joshua Bronson 2ab42ade03 Minor improvements, mostly to docs.
- Switch to Furo theme.
- Fix some links reported as broken by Sphinx's `make linkcheck`.
- No longer use autodoc private members. Avoids noisy Sphinx warnings.
- No longer generate duplicate section labels in Changelog.
  Avoids noisy Sphinx warnings.
- Remove logo, codecov badge, and add num-sponsors badge.
- Rename bidict._iter.iteritems_args_kw -> ...iteritems_args
2022-02-10 11:44:57 -05:00
Joshua Bronson a488b54334 Benchmarks, etc. 2022-02-09 11:56:57 -05:00
Joshua Bronson 1c9d7bec53 Minor code and docs changes. 2022-02-07 11:42:09 -05:00
Joshua Bronson 03d6cbc118 Compute inverse lazily, automatically add or remove __reversed__ implementations for BidictBase subclasses based on whether their backing mappings are reversible, improve mechanism for automatic dynamic generation of inverse bidict classes and use this for namedbidict, improve pickling. 2022-02-06 12:28:12 -05:00
Joshua Bronson 2057c40c69 Refactor OrderedBidictBase._node_by_key/val to node_by_korv 2022-02-02 22:52:19 -05:00
Joshua Bronson f1493e0778 Use one_of rather than sampled_from in hypothesis tests. 2022-02-02 16:55:04 -05:00
Joshua Bronson 6be66a1e0b Refactor for better performance, code quality, and maintainability. 2022-02-02 14:58:06 -05:00
Joshua Bronson 5dc6d98381 Redesign OrderedBidict for better performance and code reuse. 2022-01-31 16:45:46 -05:00
Joshua Bronson 12a9acabb7 Improvements to bidict view methods and docs. 2022-01-06 19:54:46 -05:00
Joshua Bronson 2598ccb70d rename tests/properties -> tests/property_tests 2022-01-05 19:37:59 -05:00
Joshua Bronson 69b83ff8b4 Add support for PEP 584-style dict merge operators. 2022-01-05 14:25:33 -05:00
Joshua Bronson 4fd2ffeebf Minor test improvements. 2022-01-05 12:29:35 -05:00
Joshua Bronson 7bcd478576 Remove use of slots from (non-ABC) bidict types.
Better matches mapping implementations in stdlib collections,
and saves considerable complexity and maintenance burden.
2022-01-03 18:27:00 -05:00
Joshua Bronson da250abf3e pyupgrade --py37-plus
Delete utf-8 encoding cookies from all files that require Python 3+,
where utf-8 is already the default.
2022-01-01 20:36:50 -05:00
Joshua Bronson f86ba703e4 Update copyright notices for 2022. 2022-01-01 12:59:11 -05:00
Joshua Bronson f8f896e361 Add property-based tests for keys(), values(), items() 2021-12-30 11:58:59 -05:00
Joshua Bronson c0c158a41c rm obsolete tests for Python 2 APIs 2021-12-30 10:59:38 -05:00
Joshua Bronson 9fcc793bfa Prepare for 0.21.3 release 2021-09-05 11:25:30 -04:00
Joshua Bronson e3533c77eb All bidicts provide __reversed__ in Python 3.8+ 2021-09-05 10:57:07 -04:00