Skip to content

Commit 71d5596

Browse files
Jeff Forcierbitprophet
authored andcommitted
Nuke the somewhat broken class check for Config.clone(into=)
1 parent ee9d862 commit 71d5596

File tree

3 files changed

+5
-26
lines changed

3 files changed

+5
-26
lines changed

invoke/config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,16 +1014,8 @@ def clone(self, into: Optional[Type["Config"]] = None) -> "Config":
10141014
:returns:
10151015
A `.Config`, or an instance of the class given to ``into``.
10161016
1017-
:raises:
1018-
``TypeError``, if ``into`` is given a value and that value is not a
1019-
`.Config` subclass.
1020-
10211017
.. versionadded:: 1.0
10221018
"""
1023-
# Sanity check for 'into'
1024-
if into is not None and not issubclass(into, self.__class__):
1025-
err = "'into' must be a subclass of {}!"
1026-
raise TypeError(err.format(self.__class__.__name__))
10271019
# Construct new object
10281020
klass = self.__class__ if into is None else into
10291021
# Also allow arbitrary constructor kwargs, for subclasses where passing

sites/www/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
- :feature:`-` Remove the somewhat inaccurate subclass requirement around
6+
`~invoke.config.Config`'s ``.clone(into=...)`` constructor call. It was
7+
broken for certain use cases (such as trying to clone one subclass into a
8+
sibling subclass, which would yield a ``TypeError``) and is irrelevant if one
9+
is using the new type annotations.
510
- :release:`2.1.3 <2023-06-14>`
611
- :bug:`944` After the release of 2.1, package-style task modules started
712
looking in the wrong place for project-level config files (inside one's eg

tests/config.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,24 +1039,6 @@ def is_not_required(self):
10391039
c2 = c.clone()
10401040
assert c2.meh == "okay"
10411041

1042-
def raises_TypeError_if_value_is_not_Config_subclass(self):
1043-
try:
1044-
Config().clone(into=17)
1045-
except TypeError:
1046-
pass
1047-
else:
1048-
assert False, "Non-class obj did not raise TypeError!"
1049-
1050-
class Foo:
1051-
pass
1052-
1053-
try:
1054-
Config().clone(into=Foo)
1055-
except TypeError:
1056-
pass
1057-
else:
1058-
assert False, "Non-subclass did not raise TypeError!"
1059-
10601042
def resulting_clones_are_typed_as_new_class(self):
10611043
class MyConfig(Config):
10621044
pass

0 commit comments

Comments
 (0)