diff --git a/.bumpversion.cfg b/.bumpversion.cfg
index 94c7ab7..cf0d61c 100644
--- a/.bumpversion.cfg
+++ b/.bumpversion.cfg
@@ -1,5 +1,5 @@
[bumpversion]
-current_version = 3.4.0
+current_version = 3.4.1
[bumpversion:file:Makefile]
search = CURRENT_VERSION = {current_version}
diff --git a/.gitignore b/.gitignore
index f8d4832..198f120 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,3 +106,6 @@ ENV/
# PyCharm
.idea/
+
+# vscode
+.vscode/
diff --git a/AUTHORS.rst b/AUTHORS.rst
index a83954d..13dc63a 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -3,3 +3,4 @@ Authors
=======
* Rodrigo Martins de Oliveira - https://github.com/allrod5
+* Craig Minihan - https://github.com/craigminihan
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 34c80e1..db23567 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,11 @@
Changelog
=========
+3.4.1 (2020-05-11)
+------------------
+
+* Fix the use of named args by the caller breaking autowired functions injection
+
3.4.0 (2020-05-09)
------------------
diff --git a/Makefile b/Makefile
index 66ba434..2fc986d 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,7 @@ docs:
make html -B
cp -a build/html/. docs
-CURRENT_VERSION = 3.4.0
+CURRENT_VERSION = 3.4.1
.PHONY: bump-patch-version
bump-patch-version:
diff --git a/docs/.buildinfo b/docs/.buildinfo
index 4591851..b0945dd 100644
--- a/docs/.buildinfo
+++ b/docs/.buildinfo
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
-config: e8b2b421cce8e7ab698d3e3acbafebee
+config: fdb100afd8af971a7f6d7bb34cc70893
tags: 645f666f9bcd5a90fca523b33c5a78b7
diff --git a/docs/_modules/index.html b/docs/_modules/index.html
index 2cf0d24..f6ed143 100644
--- a/docs/_modules/index.html
+++ b/docs/_modules/index.html
@@ -3,7 +3,7 @@
- Overview: module code — injectable 3.4.0 documentation
+ Overview: module code — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -106,8 +106,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/autowiring/autowired_decorator.html b/docs/_modules/injectable/autowiring/autowired_decorator.html
index 641cfba..ee07da3 100644
--- a/docs/_modules/injectable/autowiring/autowired_decorator.html
+++ b/docs/_modules/injectable/autowiring/autowired_decorator.html
@@ -3,7 +3,7 @@
- injectable.autowiring.autowired_decorator — injectable 3.4.0 documentation
+ injectable.autowiring.autowired_decorator — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -117,10 +117,10 @@ Source code for injectable.autowiring.autowired_decorator
if
parameter.name in bound_arguments:
continue
dependency = parameter.annotation.inject()
-
if parameter.kind is parameter.KEYWORD_ONLY:
-
kwargs[parameter.name] = dependency
-
else:
+
if parameter.kind is parameter.POSITIONAL_ONLY:
args.append(dependency)
+
else:
+
kwargs[parameter.name] = dependency
return func(*args, **kwargs)
@@ -173,8 +173,8 @@
Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/autowiring/autowired_type.html b/docs/_modules/injectable/autowiring/autowired_type.html
index d9d3b87..fb8a9a0 100644
--- a/docs/_modules/injectable/autowiring/autowired_type.html
+++ b/docs/_modules/injectable/autowiring/autowired_type.html
@@ -3,7 +3,7 @@
-
injectable.autowiring.autowired_type — injectable 3.4.0 documentation
+
injectable.autowiring.autowired_type — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -236,8 +236,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/container/injectable.html b/docs/_modules/injectable/container/injectable.html
index 040c3f8..25dff7a 100644
--- a/docs/_modules/injectable/container/injectable.html
+++ b/docs/_modules/injectable/container/injectable.html
@@ -3,7 +3,7 @@
- injectable.container.injectable — injectable 3.4.0 documentation
+ injectable.container.injectable — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -143,8 +143,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/container/injection_container.html b/docs/_modules/injectable/container/injection_container.html
index c8b22eb..d15048d 100644
--- a/docs/_modules/injectable/container/injection_container.html
+++ b/docs/_modules/injectable/container/injection_container.html
@@ -3,7 +3,7 @@
- injectable.container.injection_container — injectable 3.4.0 documentation
+ injectable.container.injection_container — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -282,8 +282,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/container/load_injection_container.html b/docs/_modules/injectable/container/load_injection_container.html
index f8a7d90..7124dbd 100644
--- a/docs/_modules/injectable/container/load_injection_container.html
+++ b/docs/_modules/injectable/container/load_injection_container.html
@@ -3,7 +3,7 @@
- injectable.container.load_injection_container — injectable 3.4.0 documentation
+ injectable.container.load_injection_container — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -138,8 +138,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/errors/autowiring_error.html b/docs/_modules/injectable/errors/autowiring_error.html
index ac527bf..75f674c 100644
--- a/docs/_modules/injectable/errors/autowiring_error.html
+++ b/docs/_modules/injectable/errors/autowiring_error.html
@@ -3,7 +3,7 @@
- injectable.errors.autowiring_error — injectable 3.4.0 documentation
+ injectable.errors.autowiring_error — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -100,8 +100,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/errors/injection_error.html b/docs/_modules/injectable/errors/injection_error.html
index f5884a3..c1a1a56 100644
--- a/docs/_modules/injectable/errors/injection_error.html
+++ b/docs/_modules/injectable/errors/injection_error.html
@@ -3,7 +3,7 @@
- injectable.errors.injection_error — injectable 3.4.0 documentation
+ injectable.errors.injection_error — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -100,8 +100,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/injection/inject.html b/docs/_modules/injectable/injection/inject.html
index a75e655..95999e9 100644
--- a/docs/_modules/injectable/injection/inject.html
+++ b/docs/_modules/injectable/injection/inject.html
@@ -3,7 +3,7 @@
- injectable.injection.inject — injectable 3.4.0 documentation
+ injectable.injection.inject — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -267,8 +267,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/injection/injectable_decorator.html b/docs/_modules/injectable/injection/injectable_decorator.html
index e265484..9f2f3de 100644
--- a/docs/_modules/injectable/injection/injectable_decorator.html
+++ b/docs/_modules/injectable/injection/injectable_decorator.html
@@ -3,7 +3,7 @@
- injectable.injection.injectable_decorator — injectable 3.4.0 documentation
+ injectable.injection.injectable_decorator — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -153,8 +153,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/injection/injectable_factory_decorator.html b/docs/_modules/injectable/injection/injectable_factory_decorator.html
index 4b07d32..ee9b73c 100644
--- a/docs/_modules/injectable/injection/injectable_factory_decorator.html
+++ b/docs/_modules/injectable/injection/injectable_factory_decorator.html
@@ -3,7 +3,7 @@
- injectable.injection.injectable_factory_decorator — injectable 3.4.0 documentation
+ injectable.injection.injectable_factory_decorator — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -170,8 +170,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/testing/clear_injectables_util.html b/docs/_modules/injectable/testing/clear_injectables_util.html
index 99fbb0e..0e073ff 100644
--- a/docs/_modules/injectable/testing/clear_injectables_util.html
+++ b/docs/_modules/injectable/testing/clear_injectables_util.html
@@ -3,7 +3,7 @@
- injectable.testing.clear_injectables_util — injectable 3.4.0 documentation
+ injectable.testing.clear_injectables_util — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -129,8 +129,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/testing/register_injectables_util.html b/docs/_modules/injectable/testing/register_injectables_util.html
index 09d6e5c..f2e26e3 100644
--- a/docs/_modules/injectable/testing/register_injectables_util.html
+++ b/docs/_modules/injectable/testing/register_injectables_util.html
@@ -3,7 +3,7 @@
- injectable.testing.register_injectables_util — injectable 3.4.0 documentation
+ injectable.testing.register_injectables_util — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -150,8 +150,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_modules/injectable/testing/reset_injection_container_util.html b/docs/_modules/injectable/testing/reset_injection_container_util.html
index 193b2ff..a1973c9 100644
--- a/docs/_modules/injectable/testing/reset_injection_container_util.html
+++ b/docs/_modules/injectable/testing/reset_injection_container_util.html
@@ -3,7 +3,7 @@
- injectable.testing.reset_injection_container_util — injectable 3.4.0 documentation
+ injectable.testing.reset_injection_container_util — injectable 3.4.1 documentation
@@ -28,7 +28,7 @@
Navigation
@@ -113,8 +113,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/_static/documentation_options.js b/docs/_static/documentation_options.js
index a281c2e..cd40594 100644
--- a/docs/_static/documentation_options.js
+++ b/docs/_static/documentation_options.js
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
- VERSION: '3.4.0',
+ VERSION: '3.4.1',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',
diff --git a/docs/authors.html b/docs/authors.html
index 4451ce5..2e6880b 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -3,7 +3,7 @@
- Authors — injectable 3.4.0 documentation
+ Authors — injectable 3.4.1 documentation
@@ -30,7 +30,7 @@
Navigation
@@ -50,6 +50,7 @@ Navigation
Authors
@@ -113,8 +114,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/changelog.html b/docs/changelog.html
index 50e057c..3430b4f 100644
--- a/docs/changelog.html
+++ b/docs/changelog.html
@@ -3,7 +3,7 @@
- Changelog — injectable 3.4.0 documentation
+ Changelog — injectable 3.4.1 documentation
@@ -29,7 +29,7 @@
Navigation
@@ -48,7 +48,13 @@ Navigation
Changelog
-
3.4.0 (2020-05-09)
+
3.4.1 (2020-05-11)
+
+
+
-
-
3.3.0 (2020-04-20)
+
-
-
3.2.1 (2020-04-19)
+
+
3.2.1 (2020-04-19)
InjectionContainer::load
is more resilient against duplicated injectablesregistering
@@ -73,32 +79,32 @@ 3.2.1 (2020-04-19)
@@ -189,8 +189,8 @@
Navigation
\ No newline at end of file
diff --git a/docs/usage/optional_injection.html b/docs/usage/optional_injection.html
index 64784ac..7205837 100644
--- a/docs/usage/optional_injection.html
+++ b/docs/usage/optional_injection.html
@@ -3,7 +3,7 @@
-
Optional Injection Example — injectable 3.4.0 documentation
+
Optional Injection Example — injectable 3.4.1 documentation
@@ -30,7 +30,7 @@
Navigation
@@ -160,8 +160,8 @@
Navigation
\ No newline at end of file
diff --git a/docs/usage/qualifier_overloading.html b/docs/usage/qualifier_overloading.html
index 56ad92d..8bee2ff 100644
--- a/docs/usage/qualifier_overloading.html
+++ b/docs/usage/qualifier_overloading.html
@@ -3,7 +3,7 @@
-
Qualifier Overloading Example — injectable 3.4.0 documentation
+
Qualifier Overloading Example — injectable 3.4.1 documentation
@@ -30,7 +30,7 @@
Navigation
@@ -211,8 +211,8 @@
Navigation
\ No newline at end of file
diff --git a/docs/usage/singletons.html b/docs/usage/singletons.html
index a2bc0fc..126f261 100644
--- a/docs/usage/singletons.html
+++ b/docs/usage/singletons.html
@@ -3,7 +3,7 @@
-
Singletons Example — injectable 3.4.0 documentation
+
Singletons Example — injectable 3.4.1 documentation
@@ -30,7 +30,7 @@
Navigation
@@ -196,8 +196,8 @@ Navigation
\ No newline at end of file
diff --git a/docs/usage/testing_example.html b/docs/usage/testing_example.html
index 66fb938..6570ecd 100644
--- a/docs/usage/testing_example.html
+++ b/docs/usage/testing_example.html
@@ -3,7 +3,7 @@
- Testing Example — injectable 3.4.0 documentation
+ Testing Example — injectable 3.4.1 documentation
@@ -30,7 +30,7 @@
Navigation
@@ -173,8 +173,8 @@ Navigation
\ No newline at end of file
diff --git a/injectable/autowiring/autowired_decorator.py b/injectable/autowiring/autowired_decorator.py
index b471617..30fd86f 100644
--- a/injectable/autowiring/autowired_decorator.py
+++ b/injectable/autowiring/autowired_decorator.py
@@ -69,10 +69,10 @@ def wrapper(*args, **kwargs):
if parameter.name in bound_arguments:
continue
dependency = parameter.annotation.inject()
- if parameter.kind is parameter.KEYWORD_ONLY:
- kwargs[parameter.name] = dependency
- else:
+ if parameter.kind is parameter.POSITIONAL_ONLY:
args.append(dependency)
+ else:
+ kwargs[parameter.name] = dependency
return func(*args, **kwargs)
diff --git a/setup.py b/setup.py
index 74e1633..cc5d8a2 100644
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@ def read(*names, **kwargs):
setup(
name="injectable",
- version="3.4.0",
+ version="3.4.1",
packages=find_packages(
exclude=(
"tests",
diff --git a/tests/fixes/issue_15/issue_15_fix_test.py b/tests/fixes/issue_15/issue_15_fix_test.py
new file mode 100644
index 0000000..ba49df6
--- /dev/null
+++ b/tests/fixes/issue_15/issue_15_fix_test.py
@@ -0,0 +1,28 @@
+"""
+Test the fix for the issue 15:
+Using named args breaks injectable
+https://github.com/allrod5/injectable/issues/15
+
+Injectable 3.4.0 attempted to always inject autowired parameters as positional args
+which may result in passing a duplicated parameter when the caller passes a
+non-keyword-only parameter as named arg.
+
+This issue was fixed in injectable 3.4.1.
+"""
+from injectable import injectable, autowired, Autowired, load_injection_container
+
+
+@injectable
+class Foo:
+ pass
+
+
+@autowired
+def bar(qux, foo: Autowired(Foo)):
+ assert qux == "QUX"
+ assert foo is not None
+
+
+def test_issue_15_fix():
+ load_injection_container()
+ bar(qux="QUX")
diff --git a/tests/unit/autowiring/autowired_decorator_unit_test.py b/tests/unit/autowiring/autowired_decorator_unit_test.py
index 7778082..320f11c 100644
--- a/tests/unit/autowiring/autowired_decorator_unit_test.py
+++ b/tests/unit/autowiring/autowired_decorator_unit_test.py
@@ -164,3 +164,24 @@ def f(a: AutowiredMockA, b: AutowiredMockB, c: AutowiredMockC):
assert parameters["a"] is None
assert parameters["b"] is AutowiredMockB.inject()
assert parameters["c"] is None
+
+ def test__autowired__with_named_args_defined_by_the_caller(self):
+ # given
+ AutowiredMockA = MagicMock(spec=_Autowired)
+ AutowiredMockB = MagicMock(spec=_Autowired)
+ AutowiredMockC = MagicMock(spec=_Autowired)
+
+ @autowired
+ def f(a: AutowiredMockA, b: AutowiredMockB, c: AutowiredMockC):
+ return {"a": a, "b": b, "c": c}
+
+ # when
+ parameters = f(None, b=None)
+
+ # then
+ assert AutowiredMockA.inject.called is False
+ assert AutowiredMockB.inject.called is False
+ assert AutowiredMockC.inject.called is True
+ assert parameters["a"] is None
+ assert parameters["b"] is None
+ assert parameters["c"] is AutowiredMockC.inject()
diff --git a/tests/unit/python_3_8_only/__init__.py b/tests/unit/python_3_8_only/__init__.py
new file mode 100644
index 0000000..28cfa68
--- /dev/null
+++ b/tests/unit/python_3_8_only/__init__.py
@@ -0,0 +1,5 @@
+import sys
+import pytest
+
+if sys.version_info[:2] < (3, 8):
+ pytest.skip("Skipping Python 3.8+-only tests", allow_module_level=True)
diff --git a/tests/unit/python_3_8_only/autowiring/__init__.py b/tests/unit/python_3_8_only/autowiring/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/unit/python_3_8_only/autowiring/autowired_decorator_py38_unit_test.py b/tests/unit/python_3_8_only/autowiring/autowired_decorator_py38_unit_test.py
new file mode 100644
index 0000000..ec44f9b
--- /dev/null
+++ b/tests/unit/python_3_8_only/autowiring/autowired_decorator_py38_unit_test.py
@@ -0,0 +1,32 @@
+from unittest.mock import MagicMock
+
+from injectable import autowired
+from injectable.autowiring.autowired_type import _Autowired
+
+
+class TestAutowiredDecoratorPy38:
+ def test__autowired__with_positional_only_args(self):
+ # given
+ AutowiredMockA = MagicMock(spec=_Autowired)
+ AutowiredMockB = MagicMock(spec=_Autowired)
+ AutowiredMockC = MagicMock(spec=_Autowired)
+
+ @autowired
+ def f(
+ a: AutowiredMockA,
+ /, # noqa: E999, E225
+ b: AutowiredMockB,
+ c: AutowiredMockC,
+ ):
+ return {"a": a, "b": b, "c": c}
+
+ # when
+ parameters = f(b=None)
+
+ # then
+ assert AutowiredMockA.inject.called is True
+ assert AutowiredMockB.inject.called is False
+ assert AutowiredMockC.inject.called is True
+ assert parameters["a"] is AutowiredMockA.inject()
+ assert parameters["b"] is None
+ assert parameters["c"] is AutowiredMockC.inject()