Commit 25087fd
authored
Validate more about overrides on untyped methods (#17276)
This commit fixes #9618 by making MyPy always complain if a method
overrides a base class method marked as `@final`.
In the process, it also adds a few additional validations:
- Always verify the `@override` decorator, which ought to be pretty
backward-compatible for most projects assuming that strict override
checks aren't enabled by default (and it appears to me that
`--enable-error-code explicit-override` is off by default)
- Verify that the method signature is compatible (which in practice
means only arity and argument name checks) *if* the
`--check-untyped-defs` flag is set; it seems unlikely that a user would
want mypy to validate the bodies of untyped functions but wouldn't want
to be alerted about incompatible overrides.
Note: I did also explore enabling the signature compatibility check for
all code, which in principle makes sense. But the mypy_primer results
indicated that there would be backward compability issues because too
many libraries rely on us not validating this:
#172741 parent 0871c93 commit 25087fd
4 files changed
Lines changed: 49 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
1007 | | - | |
| 1007 | + | |
1008 | 1008 | | |
1009 | 1009 | | |
1010 | 1010 | | |
| |||
1913 | 1913 | | |
1914 | 1914 | | |
1915 | 1915 | | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
1916 | 1922 | | |
1917 | 1923 | | |
1918 | | - | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
1919 | 1927 | | |
1920 | 1928 | | |
1921 | 1929 | | |
| |||
1924 | 1932 | | |
1925 | 1933 | | |
1926 | 1934 | | |
1927 | | - | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
1928 | 1939 | | |
1929 | 1940 | | |
1930 | 1941 | | |
| |||
1945 | 1956 | | |
1946 | 1957 | | |
1947 | 1958 | | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
| 1959 | + | |
| 1960 | + | |
1952 | 1961 | | |
1953 | 1962 | | |
1954 | 1963 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
619 | 622 | | |
620 | 623 | | |
621 | 624 | | |
| |||
938 | 941 | | |
939 | 942 | | |
940 | 943 | | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
941 | 947 | | |
942 | 948 | | |
943 | 949 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
759 | 774 | | |
760 | 775 | | |
761 | 776 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3228 | 3228 | | |
3229 | 3229 | | |
3230 | 3230 | | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
0 commit comments