Skip to content

Commit 8563676

Browse files
committed
Deprecate "target profession" and "current profession" kwargs
This library is being stripped back to a more basic form. There is now a PendingDeprecationWarning if users use either "target profession" or "current profession" keyword arguments, and in version 7 they will be fully deprecated. Please consider subclassing these classes if you wish to continue using these keyword arguments!
1 parent 7300e33 commit 8563676

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

example.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
first name,last name,email,role,organisation,grade,current profession,target profession
1+
first name,last name,email,role,organisation,grade,profession

matching/mentee.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import TYPE_CHECKING
23

34
from matching.person import Person
@@ -13,9 +14,16 @@ def __init__(self, **kwargs):
1314
they're in at the moment
1415
:param kwargs:
1516
"""
16-
self.target_profession = kwargs.get(
17-
"target profession", kwargs.get("current profession")
18-
)
17+
if (profession := kwargs.get("target profession")) is not None:
18+
warnings.warn(
19+
"In version 7, 'target profession' will be deprecated in favour of"
20+
" 'profession'. If you need to keep using 'target profession', please"
21+
" subclass Mentee",
22+
PendingDeprecationWarning,
23+
)
24+
self.target_profession = profession
25+
else:
26+
self.profession = self.target_profession = kwargs.get("profession", "")
1927
super(Mentee, self).__init__(**kwargs)
2028

2129
@property

matching/person.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import List, Dict, Union
23

34
CorePersonDict = Dict[str, Dict[str, Union[str, int]]]
@@ -13,7 +14,16 @@ def __init__(self, **kwargs):
1314
"""
1415
self.grade: int = int(kwargs.get("grade"))
1516
self.organisation: str = kwargs.get("organisation", None)
16-
self.current_profession: str = kwargs.get("current profession", None)
17+
if (profession := kwargs.get("current profession")) is not None:
18+
warnings.warn(
19+
"In version 7, 'current profession' will be deprecated in favour of"
20+
" 'profession'. If you need to keep using 'current profession', please"
21+
" subclass Person",
22+
PendingDeprecationWarning,
23+
)
24+
self.current_profession = self.profession = profession
25+
else:
26+
self.profession = self.current_profession = kwargs.get("profession", "")
1727
self.email = kwargs.get("email", None)
1828
self.first_name = kwargs.get("first name", None)
1929
self.last_name = kwargs.get("last name", None)
@@ -55,6 +65,7 @@ def core_to_dict(self) -> CorePersonDict:
5565
"role": self.role,
5666
"organisation": self.organisation,
5767
"grade": self.grade,
68+
"profession": self.profession,
5869
"current profession": self.current_profession,
5970
}
6071
}

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def base_data() -> dict:
6767
"role": "N/A",
6868
"organisation": "Department of Fun",
6969
"grade": 5,
70-
"current profession": "Policy",
70+
"profession": "Policy",
7171
}
7272

7373

tests/test_person.py

+9
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ def test_person_is_deserializable(
4949
person_as_dict = json.loads(person_as_json)
5050
recreated_person = ParticipantFactory.create_from_dict(person_as_dict)
5151
assert recreated_person == test_person
52+
53+
@pytest.mark.parametrize(
54+
["match_class", "attribute"],
55+
[(Person, "current profession"), (Mentee, "target profession")],
56+
)
57+
def test_deprecation_warnings(self, match_class, attribute, base_data):
58+
with pytest.deprecated_call():
59+
base_data[attribute] = "error"
60+
match_class(**base_data)

0 commit comments

Comments
 (0)