Skip to content

Commit

Permalink
fix mutability api error
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiommendes committed Sep 17, 2016
1 parent eb1b9cf commit 7931736
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.6.1
0.6.3
24 changes: 4 additions & 20 deletions boilerplate.ini
Expand Up @@ -2,47 +2,31 @@
project = smallvectors
author = Fábio Macêdo Mendes
email = fabiomacedomendes@gmail.com
version = 0.4.6
version = 0.6.2
license = gpl
pyname = smallvectors
has_script = false
python_version = both
boilerplate_version = 1

[file hashes]
.gitignore = iu2Zn1vki51Un7bnWFivjQ==

INSTALL.rst = 9lb/d88HQ0hGezbwoGNTRg==

LICENSE = FuV5NeyW3bl3fBm/fWRkvw==

tasks.py = 6GOUg08jHdzGhTHggdHrsA==

setup.py = 4BUfgPZVm3X66jTMjaROLw==

MANIFEST.in = BR29dThJGj3LpFi457HDsw==

requirements.txt = 9/H6jW0guTB5y4aYQ+29FA==

requirements-dev.txt = IrFEvOtt6TH8c3X1z/Qgrg==

src/smallvectors/__meta__.py = gbgEMe+4FmNbN+z2nX83fw==

src/smallvectors/__main__.py = xpIZEyBOCB/MGQd7ozratA==

src/smallvectors/tests/test_smallvectors.py = nOIxlmSfvN0isYgmfQ9Aog==

docs/conf.py = aYMkaxQn7VwS9OxI8gSesg==

docs/index.rst = N4fyFQVu5mr+VnIghp/imQ==

docs/install.rst = uEvES6MgO5srBNLXAVqL/Q==

docs/license.rst = T7JCt0IDBksEuohsOM3rxQ==

docs/apidoc.rst = wbC8YV52W3pps8wK3+VTlw==

docs/warning.rst = qiipkkPaw0hlzLnokVKg0w==

docs/make.bat = PQXLkE61OdGkBLrufEsxVQ==

docs/Makefile = yt1XIoUMNcKdnqcIy7pcGQ==


2 changes: 1 addition & 1 deletion src/smallvectors.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: smallvectors
Version: 0.6.1
Version: 0.6.2
Summary: Linear algebra objects for small dimensions.
Home-page: http://github.com/fabiommendes/smallvectors/
Author: Fábio Macêdo Mendes
Expand Down
2 changes: 1 addition & 1 deletion src/smallvectors/__meta__.py
@@ -1,2 +1,2 @@
__version__ = '0.6.1'
__version__ = '0.6.2'
__author__ = 'Fábio Macêdo Mendes'
38 changes: 21 additions & 17 deletions src/smallvectors/core/mutability.py
Expand Up @@ -149,27 +149,31 @@ def get_complementary(cls):
Return mutable from immutable and vice-versa.
"""

# Get origin type and its name
if cls.__origin__ is None:
origin = cls
else:
origin = cls.__origin__
mod = sys.modules[cls.__module__]

# Get class
if issubclass(cls, Mutable):
is_mutable = False
other_origin = getattr(mod, origin.__name__[1:])
name = cls.__name__
origin_name = origin.__name__

# Check if the mutability naming convention is followed. If so, compute the
# complementary origin name. If not, raise an attribute error.
is_mutable = issubclass(cls, Mutable)
if is_mutable and not origin_name.startswith('m'):
raise AttributeError('no immutable class associated with %s' % name)
elif is_mutable:
complementary_name = origin_name[1:]
else:
is_mutable = True
other_origin = getattr(mod, 'm' + origin.__name__)
complementary_name = 'm' + origin_name

# Apply parameters
if (cls.__parameters__ and
not all(isinstance(x, type) for x in cls.__parameters__)):
other = other_origin[cls.__parameters__]
else:
other = other_origin
# We check for the complementary class in the module that defines the origin
# class
mod = sys.modules[origin.__module__]
complementary_origin = getattr(mod, complementary_name)

# Return
assert issubclass(other, (Mutable if is_mutable else Immutable))
return other
# Apply parameters, if necessary
if cls is origin:
return complementary_origin
else:
return complementary_origin[cls.__parameters__]

0 comments on commit 7931736

Please sign in to comment.