From: Bob Halley Date: Sat, 6 May 2023 18:21:36 +0000 (-0700) Subject: Deal with "in" changes for enums in python 3.12 X-Git-Tag: v2.4.0rc1~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=83670766f84189c30450d8beed6a896bf9207fe1;p=thirdparty%2Fdnspython.git Deal with "in" changes for enums in python 3.12 In python 3.12, "in" for enums tests values as well, so something like "12345 in dns.rdatatype.RdataType" will now return True. This broke some logic guarding against registering a known-but-unimplmemented type code point with a class that didn't have the right name. We now just give up on this test as it will never be a real problem. We change a few related tests to be more sensible. --- diff --git a/dns/rdata.py b/dns/rdata.py index 66c07eec..f0b340c7 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -884,14 +884,6 @@ def register_type( existing_cls = get_rdata_class(rdclass, rdtype) if existing_cls != GenericRdata or dns.rdatatype.is_metatype(rdtype): raise RdatatypeExists(rdclass=rdclass, rdtype=rdtype) - try: - if ( - rdtype in dns.rdatatype.RdataType - and dns.rdatatype.RdataType(rdtype).name != rdtype_text - ): - raise RdatatypeExists(rdclass=rdclass, rdtype=rdtype) - except ValueError: - pass _rdata_classes[(rdclass, rdtype)] = getattr( implementation, rdtype_text.replace("-", "_") ) diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 73023693..b9cfea8e 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -586,13 +586,12 @@ class RdataTestCase(unittest.TestCase): rd = dns.rdata.from_text("in", "rrsig", text) self.assertEqual(repr(rd), "") - def test_bad_registration_implementing_known_type_with_wrong_name(self): - # Try to register an implementation at the MG codepoint that isn't - # called "MG" + def test_registration_implementing_known_and_implemented_type(self): + # Try to register an implementation at the A codepoint. with self.assertRaises(dns.rdata.RdatatypeExists): - dns.rdata.register_type(None, dns.rdatatype.MG, "NOTMG") + dns.rdata.register_type(None, dns.rdatatype.A, "ANYTHING") - def test_registration_implementing_known_type_with_right_name(self): + def test_registration_of_known_but_unimplmented_type(self): # Try to register an implementation at the MD codepoint dns.rdata.register_type(tests.md_module, dns.rdatatype.MD, "MD") rd = dns.rdata.from_text("in", "md", "foo.")