File: test_new_union__py3_10.py

package info (click to toggle)
python-overrides 7.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: python: 1,661; sh: 5; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations

import sys

import pytest
from overrides import override


class A:
    def f(self) -> int | str:
        return 1


def test_should_allow_reducing_type():
    class B(A):
        @override
        def f(self) -> int:
            return 1

    assert B().f() == 1


@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires Python3.10 or higher")
def test_should_not_allow_increasing_type():
    with pytest.raises(TypeError):

        class C(A):
            @override
            def f(self) -> int | str | list[str]:
                return []

        assert False, "should not go here"