pydantic-core icon indicating copy to clipboard operation
pydantic-core copied to clipboard

[Heads up] test_invalid_regex fails with Python 3.13.0a3 (re.Error renamed to PatternError)

Open befeleme opened this issue 1 year ago • 3 comments

When building pydantic-code for Fedora Linux with Python 3.13.0a3, one of the tests fails. re.Error has been renamed to PatternError: https://docs.python.org/dev/whatsnew/3.13.html#re


________________________ test_invalid_regex[python-re] _________________________

engine = 'python-re'

    @pytest.mark.parametrize('engine', [None, 'rust-regex', 'python-re'])
    def test_invalid_regex(engine):
        # TODO uncomment and fix once #150 is done
        # with pytest.raises(SchemaError) as exc_info:
        #     SchemaValidator({'type': 'str', 'pattern': 123})
        # assert exc_info.value.args[0] == (
        #     'Error building "str" validator:\n  TypeError: \'int\' object cannot be converted to \'PyString\''
        # )
        with pytest.raises(SchemaError) as exc_info:
            SchemaValidator(core_schema.str_schema(pattern='(abc', regex_engine=engine))
    
        if engine is None or engine == 'rust-regex':
            assert exc_info.value.args[0] == (
                'Error building "str" validator:\n'
                '  SchemaError: regex parse error:\n'
                '    (abc\n'
                '    ^\n'
                'error: unclosed group'
            )
        elif engine == 'python-re':
>           assert exc_info.value.args[0] == (
                'Error building "str" validator:\n  error: missing ), unterminated subpattern at position 0'
            )
E           assert 'Error buildi...at position 0' == 'Error buildi...at position 0'
E               Error building "str" validator:
E             -   error: missing ), unterminated subpattern at position 0
E             +   PatternError: missing ), unterminated subpattern at position 0
E             ?   ++++ +++

tests/validators/test_string.py:190: AssertionError
=========================== short test summary info ============================

befeleme avatar Jan 31 '24 12:01 befeleme

Thanks for the report. Is this packaging with 3.13 or just a local dev build?

Upstream in PyO3 I haven't attempted to support 3.13 yet, so while it's nice to see it "works" I'd be fearful that other stuff might be subtly broken too. I intend to make it more clear to users what the expected outcome is: https://github.com/PyO3/pyo3/issues/3555

davidhewitt avatar Feb 01 '24 10:02 davidhewitt

That's a part of an early effort to integrate Python 3.13 into Fedora - we package everything with the consecutive alpha releases to provide the early feedback all the interested parties. It's not yet intended as a distribution package heading to the users, but the sooner we've got pydantic-core working, the sooner we can build packages that depend on it.

befeleme avatar Feb 01 '24 12:02 befeleme

Understood, thanks. Looks like 3.13 is on GitHub actions, so we could begin testing it and at least trying to make it do sensible things. I wouldn't bet on it being reliable until I've had some time to try to get PyO3 synchronized.

davidhewitt avatar Feb 12 '24 18:02 davidhewitt