Skip to content
Snippets Groups Projects
Commit 6bae1492 authored by Sandro Tosi's avatar Sandro Tosi
Browse files

New upstream version 1.9.0

parent e8d502ba
No related branches found
No related tags found
No related merge requests found
[bumpversion]
current_version = 1.8.0
current_version = 1.9.0
commit = True
tag = True
......
......@@ -54,4 +54,4 @@ default_context:
version_manager: bump2version
website: https://blog.ionelmc.ro
year_from: '2014'
year_to: '2022'
year_to: '2023'
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
.git_archival.txt export-subst
......@@ -5,20 +5,20 @@
exclude: '^(\.tox|ci/templates|\.bumpversion\.cfg)(/|$)'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: v5.11.3
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
......@@ -2,6 +2,16 @@
Changelog
=========
1.9.0 (2023-01-04)
------------------
* Added support for matrix multiplication operator (``@``).
* Should have all the wheels now (including the manylinux ones).
* Bumped minimum version requirements for setuptools and setuptools-scm.
* Switched the default pure python fallback implementation to the "simple" one (when you ``from lazy_object_proxy import Proxy``
and the C extension is not available).
Previously the "slots" implementation was used but as it turns out it is slower on Python 3.
1.8.0 (2022-10-26)
------------------
......
......@@ -49,7 +49,7 @@ To set up `python-lazy-object-proxy` for local development:
Now you can make your changes locally.
4. When you're done making changes run all the checks and docs builder with `tox <https://tox.readthedocs.io/en/latest/install.html>`_ one command::
4. When you're done making changes run all the checks and docs builder with `tox <https://tox.wiki/en/latest/installation.html>`_ one command::
tox
......
BSD 2-Clause License
Copyright (c) 2014-2022, Ionel Cristian Mărieș. All rights reserved.
Copyright (c) 2014-2023, Ionel Cristian Mărieș. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
......
......@@ -51,9 +51,9 @@ Overview
:alt: Supported implementations
:target: https://pypi.org/project/lazy-object-proxy
.. |commits-since| image:: https://img.shields.io/github/commits-since/ionelmc/python-lazy-object-proxy/v1.8.0.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/ionelmc/python-lazy-object-proxy/v1.9.0.svg
:alt: Commits since latest release
:target: https://github.com/ionelmc/python-lazy-object-proxy/compare/v1.8.0...master
:target: https://github.com/ionelmc/python-lazy-object-proxy/compare/v1.9.0...master
......
......@@ -19,7 +19,7 @@ extensions = [
source_suffix = '.rst'
master_doc = 'index'
project = 'lazy-object-proxy'
year = '2014-2022'
year = '2014-2023'
author = 'Ionel Cristian Mărieș'
copyright = '{0}, {1}'.format(year, author)
try:
......@@ -28,7 +28,7 @@ try:
version = release = get_distribution('lazy_object_proxy').version
except Exception:
traceback.print_exc()
version = release = '1.8.0'
version = release = '1.9.0'
pygments_style = 'trac'
templates_path = ['.']
......
[build-system]
requires = [
"setuptools>=30.3.0",
"wheel",
"setuptools_scm>=3.3.1",
"setuptools>=45",
"setuptools_scm[toml]>=6.2"
]
[tool.black]
......
......@@ -74,7 +74,7 @@ setup(
use_scm_version={
'local_scheme': 'dirty-tag',
'write_to': 'src/lazy_object_proxy/_version.py',
'fallback_version': '1.8.0',
'fallback_version': '1.9.0',
},
license='BSD-2-Clause',
description='A fast and thorough lazy object proxy.',
......
......@@ -11,13 +11,13 @@ try:
from .cext import Proxy
from .cext import identity
except ImportError:
from .slots import Proxy
from .simple import Proxy
else:
copyreg.constructor(identity)
try:
from ._version import version as __version__
except ImportError:
__version__ = '1.8.0'
__version__ = '1.9.0'
__all__ = ("Proxy",)
......@@ -248,6 +248,16 @@ static PyObject *Proxy_multiply(PyObject *o1, PyObject *o2)
/* ------------------------------------------------------------------------- */
static PyObject *Proxy_matrix_multiply(PyObject *o1, PyObject *o2)
{
Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
return PyNumber_MatrixMultiply(o1, o2);
}
/* ------------------------------------------------------------------------- */
static PyObject *Proxy_remainder(PyObject *o1, PyObject *o2)
{
Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
......@@ -458,6 +468,28 @@ static PyObject *Proxy_inplace_multiply(
/* ------------------------------------------------------------------------- */
static PyObject *Proxy_inplace_matrix_multiply(
ProxyObject *self, PyObject *other)
{
PyObject *object = NULL;
Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
object = PyNumber_InPlaceMatrixMultiply(self->wrapped, other);
if (!object)
return NULL;
Py_DECREF(self->wrapped);
self->wrapped = object;
Py_INCREF(self);
return (PyObject *)self;
}
/* ------------------------------------------------------------------------- */
static PyObject *Proxy_inplace_remainder(
ProxyObject *self, PyObject *other)
{
......@@ -1239,6 +1271,8 @@ static PyNumberMethods Proxy_as_number = {
(binaryfunc)Proxy_inplace_floor_divide, /*nb_inplace_floor_divide*/
(binaryfunc)Proxy_inplace_true_divide, /*nb_inplace_true_divide*/
(unaryfunc)Proxy_index, /*nb_index*/
(binaryfunc)Proxy_matrix_multiply, /*nb_matrix_multiply*/
(binaryfunc)Proxy_inplace_matrix_multiply, /*nb_inplace_matrix_multiply*/
};
static PySequenceMethods Proxy_as_sequence = {
......
......@@ -141,6 +141,7 @@ class Proxy(with_metaclass(_ProxyMetaType)):
__add__ = make_proxy_method(operator.add)
__sub__ = make_proxy_method(operator.sub)
__mul__ = make_proxy_method(operator.mul)
__matmul__ = make_proxy_method(operator.matmul)
__truediv__ = make_proxy_method(operator.truediv)
__floordiv__ = make_proxy_method(operator.floordiv)
__mod__ = make_proxy_method(operator.mod)
......@@ -161,6 +162,9 @@ class Proxy(with_metaclass(_ProxyMetaType)):
def __rmul__(self, other):
return other * self.__wrapped__
def __rmatmul__(self, other):
return other @ self.__wrapped__
def __rdiv__(self, other):
return operator.div(other, self.__wrapped__)
......@@ -197,6 +201,7 @@ class Proxy(with_metaclass(_ProxyMetaType)):
__iadd__ = make_proxy_method(operator.iadd)
__isub__ = make_proxy_method(operator.isub)
__imul__ = make_proxy_method(operator.imul)
__imatmul__ = make_proxy_method(operator.imatmul)
__itruediv__ = make_proxy_method(operator.itruediv)
__ifloordiv__ = make_proxy_method(operator.ifloordiv)
__imod__ = make_proxy_method(operator.imod)
......
......@@ -226,6 +226,9 @@ class Proxy(with_metaclass(_ProxyMetaType)):
def __mul__(self, other):
return self.__wrapped__ * other
def __matmul__(self, other):
return self.__wrapped__ @ other
def __truediv__(self, other):
return operator.truediv(self.__wrapped__, other)
......@@ -265,6 +268,9 @@ class Proxy(with_metaclass(_ProxyMetaType)):
def __rmul__(self, other):
return other * self.__wrapped__
def __rmatmul__(self, other):
return other @ self.__wrapped__
def __rdiv__(self, other):
return operator.div(other, self.__wrapped__)
......@@ -310,8 +316,8 @@ class Proxy(with_metaclass(_ProxyMetaType)):
self.__wrapped__ *= other
return self
def __idiv__(self, other):
self.__wrapped__ = operator.idiv(self.__wrapped__, other)
def __imatmul__(self, other):
self.__wrapped__ @= other
return self
def __itruediv__(self, other):
......
......@@ -912,6 +912,38 @@ def test_mul(lop):
assert two * 3 == 2 * 3
def test_matmul(lop):
class MatmulClass:
def __init__(self, value):
self.value = value
def __matmul__(self, other):
return self.value * other.value
def __rmatmul__(self, other):
return other + self.value
one = MatmulClass(123)
two = MatmulClass(234)
assert one @ two == 28782
one = lop.Proxy(lambda: MatmulClass(123))
two = lop.Proxy(lambda: MatmulClass(234))
assert one @ two == 28782
one = lop.Proxy(lambda: MatmulClass(123))
two = MatmulClass(234)
assert one @ two == 28782
one = 123
two = lop.Proxy(lambda: MatmulClass(234))
assert one @ two == 357
one = lop.Proxy(lambda: 123)
two = lop.Proxy(lambda: MatmulClass(234))
assert one @ two == 357
def test_div(lop):
# On Python 2 this will pick up div and on Python
# 3 it will pick up truediv.
......@@ -1067,6 +1099,27 @@ def test_imul(lop):
assert type(value) == lop.Proxy
def test_imatmul(lop):
class InplaceMatmul:
value = None
def __imatmul__(self, other):
self.value = other
return self
value = InplaceMatmul()
assert value.value is None
value @= 123
assert value.value == 123
value = lop.Proxy(InplaceMatmul)
value @= 234
assert value.value == 234
if lop.kind != 'simple':
assert type(value) == lop.Proxy
def test_idiv(lop):
# On Python 2 this will pick up div and on Python
# 3 it will pick up truediv.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment