Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
befeleme opened this issue Jan 31, 2024 · 3 comments
Assignees

Comments

@befeleme
Copy link

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 ============================
@davidhewitt
Copy link
Contributor

davidhewitt commented Feb 1, 2024

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: PyO3/pyo3#3555

@befeleme
Copy link
Author

befeleme commented Feb 1, 2024

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.

@davidhewitt
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants