Skip to content

Commit c611db7

Browse files
committed
union at type joins
1 parent 69d3307 commit c611db7

File tree

8 files changed

+190
-99
lines changed

8 files changed

+190
-99
lines changed

.mypy/baseline.json

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
{
163163
"code": "no-any-expr",
164164
"column": 8,
165-
"message": "Expression has type \"Any\"",
165+
"message": "Expression type contains \"Any\" (has type \"int | Any\")",
166166
"offset": 1,
167167
"target": "mypy.build.cache_meta_from_dict"
168168
},
@@ -288,7 +288,7 @@
288288
{
289289
"code": "no-any-expr",
290290
"column": 8,
291-
"message": "Expression has type \"Any\"",
291+
"message": "Expression type contains \"Any\" (has type \"int | Any\")",
292292
"offset": 1,
293293
"target": "mypy.build.cache_meta_from_dict"
294294
},
@@ -775,24 +775,17 @@
775775
"offset": 199,
776776
"target": "mypy.build.load_baseline"
777777
},
778-
{
779-
"code": "no-any-expr",
780-
"column": 34,
781-
"message": "Expression has type \"Any\"",
782-
"offset": 7,
783-
"target": "mypy.build.load_baseline"
784-
},
785778
{
786779
"code": "no-any-expr",
787780
"column": 7,
788-
"message": "Expression has type \"Any\"",
789-
"offset": 6,
781+
"message": "Expression type contains \"Any\" (has type \"Any | bool\")",
782+
"offset": 14,
790783
"target": "mypy.build.load_baseline"
791784
},
792785
{
793786
"code": "no-any-expr",
794787
"column": 9,
795-
"message": "Expression has type \"Any\"",
788+
"message": "Expression type contains \"Any\" (has type \"Any | bool\")",
796789
"offset": 3,
797790
"target": "mypy.build.load_baseline"
798791
},
@@ -814,7 +807,7 @@
814807
"code": "no-any-expr",
815808
"column": 15,
816809
"message": "Expression type contains \"Any\" (has type \"dict[str, Any] | None\")",
817-
"offset": 32,
810+
"offset": 33,
818811
"target": "mypy.build.read_plugins_snapshot"
819812
},
820813
{
@@ -1653,7 +1646,7 @@
16531646
{
16541647
"code": "no-any-expr",
16551648
"column": 24,
1656-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1649+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
16571650
"offset": 2,
16581651
"target": "mypy.build.validate_meta"
16591652
},
@@ -1793,14 +1786,14 @@
17931786
{
17941787
"code": "no-any-expr",
17951788
"column": 38,
1796-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1789+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
17971790
"offset": 3,
17981791
"target": "mypy.build.validate_meta"
17991792
},
18001793
{
18011794
"code": "no-any-expr",
18021795
"column": 38,
1803-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1796+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
18041797
"offset": 2,
18051798
"target": "mypy.build.validate_meta"
18061799
},
@@ -1863,7 +1856,7 @@
18631856
{
18641857
"code": "no-any-expr",
18651858
"column": 11,
1866-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1859+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
18671860
"offset": 52,
18681861
"target": "mypy.build.write_cache"
18691862
},
@@ -1891,7 +1884,7 @@
18911884
{
18921885
"code": "no-any-expr",
18931886
"column": 26,
1894-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1887+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
18951888
"offset": 4,
18961889
"target": "mypy.build.write_cache"
18971890
},
@@ -1912,7 +1905,7 @@
19121905
{
19131906
"code": "no-any-expr",
19141907
"column": 48,
1915-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
1908+
"message": "Expression type contains \"Any\" (has type \"dict[str, str | int | list[str] | Mapping[str, object] | list[int] | Any]\")",
19161909
"offset": 0,
19171910
"target": "mypy.build.write_cache"
19181911
},
@@ -4698,25 +4691,74 @@
46984691
"offset": 4,
46994692
"target": "mypy.config_parser"
47004693
},
4694+
{
4695+
"code": "no-any-expr",
4696+
"column": 25,
4697+
"message": "Expression type contains \"Any\" (has type \"dict[str, (str | float) -> (int, int) | (Untyped) -> list[str] | (Untyped) -> str | (str | Sequence[str]) -> list[str]]\")",
4698+
"offset": 5,
4699+
"target": "mypy.config_parser"
4700+
},
4701+
{
4702+
"code": "no-any-expr",
4703+
"column": 4,
4704+
"message": "Expression type contains \"Any\" (has type \"(str, (Untyped) -> list[str])\")",
4705+
"offset": 3,
4706+
"target": "mypy.config_parser"
4707+
},
47014708
{
47024709
"code": "no-any-expr",
47034710
"column": 17,
47044711
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> list[str]\")",
4705-
"offset": 8,
4712+
"offset": 0,
4713+
"target": "mypy.config_parser"
4714+
},
4715+
{
4716+
"code": "no-any-expr",
4717+
"column": 17,
4718+
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> list[str]\")",
4719+
"offset": 0,
4720+
"target": "mypy.config_parser"
4721+
},
4722+
{
4723+
"code": "no-any-expr",
4724+
"column": 4,
4725+
"message": "Expression type contains \"Any\" (has type \"(str, (Untyped) -> list[str])\")",
4726+
"offset": 1,
47064727
"target": "mypy.config_parser"
47074728
},
47084729
{
47094730
"code": "no-any-expr",
47104731
"column": 13,
47114732
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> list[str]\")",
4733+
"offset": 0,
4734+
"target": "mypy.config_parser"
4735+
},
4736+
{
4737+
"code": "no-any-expr",
4738+
"column": 13,
4739+
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> list[str]\")",
4740+
"offset": 0,
4741+
"target": "mypy.config_parser"
4742+
},
4743+
{
4744+
"code": "no-any-expr",
4745+
"column": 4,
4746+
"message": "Expression type contains \"Any\" (has type \"(str, (Untyped) -> str)\")",
47124747
"offset": 1,
47134748
"target": "mypy.config_parser"
47144749
},
47154750
{
47164751
"code": "no-any-expr",
47174752
"column": 22,
47184753
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> str\")",
4719-
"offset": 1,
4754+
"offset": 0,
4755+
"target": "mypy.config_parser"
4756+
},
4757+
{
4758+
"code": "no-any-expr",
4759+
"column": 22,
4760+
"message": "Expression type contains \"Any\" (has type \"(Untyped) -> str\")",
4761+
"offset": 0,
47204762
"target": "mypy.config_parser"
47214763
},
47224764
{
@@ -6760,14 +6802,14 @@
67606802
{
67616803
"code": "no-any-expr",
67626804
"column": 24,
6763-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
6805+
"message": "Expression type contains \"Any\" (has type \"dict[str, Any] | dict[str, object]\")",
67646806
"offset": 3,
67656807
"target": "mypy.dmypy_server.Server.serve"
67666808
},
67676809
{
67686810
"code": "no-any-expr",
67696811
"column": 48,
6770-
"message": "Expression type contains \"Any\" (has type \"dict[str, Any]\")",
6812+
"message": "Expression type contains \"Any\" (has type \"dict[str, Any] | dict[str, object]\")",
67716813
"offset": 1,
67726814
"target": "mypy.dmypy_server.Server.serve"
67736815
},
@@ -8973,7 +9015,7 @@
89739015
{
89749016
"code": "no-any-expr",
89759017
"column": 26,
8976-
"message": "Expression has type \"Any\"",
9018+
"message": "Expression type contains \"Any\" (has type \"Any | StrExpr\")",
89779019
"offset": 0,
89789020
"target": "mypy.fastparse.ASTConverter.visit_FormattedValue"
89799021
},
@@ -8987,7 +9029,7 @@
89879029
{
89889030
"code": "no-any-expr",
89899031
"column": 47,
8990-
"message": "Expression has type \"Any\"",
9032+
"message": "Expression type contains \"Any\" (has type \"Any | StrExpr\")",
89919033
"offset": 0,
89929034
"target": "mypy.fastparse.ASTConverter.visit_FormattedValue"
89939035
},
@@ -11504,7 +11546,7 @@
1150411546
"code": "no-any-expr",
1150511547
"column": 30,
1150611548
"message": "Expression type contains \"Any\" (has type \"type[CallableType]\")",
11507-
"offset": 312,
11549+
"offset": 329,
1150811550
"target": "mypy.join.TypeJoinVisitor.visit_callable_type"
1150911551
},
1151011552
{
@@ -13731,7 +13773,7 @@
1373113773
{
1373213774
"code": "no-any-expr",
1373313775
"column": 32,
13734-
"message": "Expression has type \"Any\"",
13776+
"message": "Expression type contains \"Any\" (has type \"Any | None\")",
1373513777
"offset": 2,
1373613778
"target": "mypy.moduleinspect.get_package_properties"
1373713779
}
@@ -19936,7 +19978,7 @@
1993619978
{
1993719979
"code": "no-any-expr",
1993819980
"column": 8,
19939-
"message": "Expression has type \"Any\"",
19981+
"message": "Expression type contains \"Any\" (has type \"Any | list[Any]\")",
1994019982
"offset": 0,
1994119983
"target": "mypy.stubtest.verify_mypyfile"
1994219984
},
@@ -19950,7 +19992,7 @@
1995019992
{
1995119993
"code": "no-any-expr",
1995219994
"column": 8,
19953-
"message": "Expression has type \"Any\"",
19995+
"message": "Expression type contains \"Any\" (has type \"Any | list[Any]\")",
1995419996
"offset": 0,
1995519997
"target": "mypy.stubtest.verify_mypyfile"
1995619998
},
@@ -19971,14 +20013,14 @@
1997120013
{
1997220014
"code": "no-any-expr",
1997320015
"column": 20,
19974-
"message": "Expression has type \"Any\"",
20016+
"message": "Expression type contains \"Any\" (has type \"Any | list[Any]\")",
1997520017
"offset": 10,
1997620018
"target": "mypy.stubtest.verify_mypyfile"
1997720019
},
1997820020
{
1997920021
"code": "no-any-expr",
1998020022
"column": 20,
19981-
"message": "Expression has type \"Any\"",
20023+
"message": "Expression type contains \"Any\" (has type \"Any | list[Any]\")",
1998220024
"offset": 0,
1998320025
"target": "mypy.stubtest.verify_mypyfile"
1998420026
},
@@ -23906,48 +23948,6 @@
2390623948
"message": "Base type Suite becomes \"Any (from unimported type)\" due to an unfollowed import",
2390723949
"offset": 0,
2390823950
"target": "mypy.test.testinfer"
23909-
},
23910-
{
23911-
"code": "no-any-expr",
23912-
"column": 8,
23913-
"message": "Expression type contains \"Any\" (has type \"dict[int, tuple[Any, ...]]\")",
23914-
"offset": 22,
23915-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
23916-
},
23917-
{
23918-
"code": "no-any-expr",
23919-
"column": 26,
23920-
"message": "Expression type contains \"Any\" (has type \"list[dict[int, tuple[Any, ...]]]\")",
23921-
"offset": 0,
23922-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
23923-
},
23924-
{
23925-
"code": "no-any-expr",
23926-
"column": 55,
23927-
"message": "Expression type contains \"Any\" (has type \"dict[int, tuple[Any, ...]]\")",
23928-
"offset": 2,
23929-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
23930-
},
23931-
{
23932-
"code": "no-any-expr",
23933-
"column": 55,
23934-
"message": "Expression type contains \"Any\" (has type \"dict[int, tuple[Any, ...]]\")",
23935-
"offset": 4,
23936-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
23937-
},
23938-
{
23939-
"code": "no-any-expr",
23940-
"column": 55,
23941-
"message": "Expression type contains \"Any\" (has type \"dict[int, tuple[Any, ...]]\")",
23942-
"offset": 4,
23943-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
23944-
},
23945-
{
23946-
"code": "no-any-expr",
23947-
"column": 55,
23948-
"message": "Expression type contains \"Any\" (has type \"dict[int, tuple[Any, ...]]\")",
23949-
"offset": 4,
23950-
"target": "mypy.test.testinfer.OperandComparisonGroupingSuite.test_basic_cases"
2395123951
}
2395223952
],
2395323953
"mypy/test/testmerge.py": [
@@ -31424,7 +31424,7 @@
3142431424
{
3142531425
"code": "no-any-expr",
3142631426
"column": 20,
31427-
"message": "Expression has type \"Any\"",
31427+
"message": "Expression type contains \"Any\" (has type \"Any | bool\")",
3142831428
"offset": 0,
3142931429
"target": "mypyc.test.test_run.TestRun.run_case_step"
3143031430
},
@@ -31438,7 +31438,7 @@
3143831438
{
3143931439
"code": "no-any-expr",
3144031440
"column": 43,
31441-
"message": "Expression has type \"Any\"",
31441+
"message": "Expression type contains \"Any\" (has type \"Any | bool\")",
3144231442
"offset": 0,
3144331443
"target": "mypyc.test.test_run.TestRun.run_case_step"
3144431444
},
@@ -31466,7 +31466,7 @@
3146631466
{
3146731467
"code": "no-any-expr",
3146831468
"column": 40,
31469-
"message": "Expression has type \"Any\"",
31469+
"message": "Expression type contains \"Any\" (has type \"Any | bool\")",
3147031470
"offset": 22,
3147131471
"target": "mypyc.test.test_run.TestRun.run_case_step"
3147231472
},

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Basedmypy Changelog
22

33
## [Unreleased]
4+
### Enhancements
5+
- Unionize at type joins instead of common ancestor
46

57
## [1.4.0]
68
### Added

mypy/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ def load_baseline(options: Options, errors: Errors, stdout: TextIO) -> None:
11431143
# if format hasn't been found yet, it can only be 1.2
11441144
baseline_format = "1.2"
11451145
if not options.write_baseline and options.baseline_format == "default":
1146+
assert isinstance(baseline_format, str)
11461147
options.baseline_format = baseline_format
11471148
# set default baseline format
11481149
if options.write_baseline and options.baseline_format == "default":
@@ -1164,6 +1165,7 @@ def load_baseline(options: Options, errors: Errors, stdout: TextIO) -> None:
11641165
baseline_format_error(options.baseline_format, stdout, options)
11651166

11661167
if baseline_errors and targets:
1168+
assert isinstance(baseline_format, str)
11671169
errors.initialize_baseline(
11681170
cast(Dict[str, List[UnknownBaselineError]], baseline_errors),
11691171
cast(List[str], targets),

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,7 +4335,7 @@ def type_check_raise(self, e: Expression, s: RaiseStmt, optional: bool = False)
43354335

43364336
# Python3 case:
43374337
exc_type = self.named_type("builtins.BaseException")
4338-
expected_type_items = [exc_type, TypeType(exc_type)]
4338+
expected_type_items: List[Type] = [exc_type, TypeType(exc_type)]
43394339
if optional:
43404340
# This is used for `x` part in a case like `raise e from x`,
43414341
# where we allow `raise e from None`.

0 commit comments

Comments
 (0)