-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of optionals in mypy plugin (#9008)
- Loading branch information
Showing
7 changed files
with
152 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
id: Optional[int] | ||
|
||
|
||
class Bar(BaseModel): | ||
foo: Optional[Foo] | ||
|
||
|
||
class Baz(Bar): | ||
name: str | ||
|
||
|
||
b = Bar(foo={'id': 1}) | ||
assert b.foo.id == 1 | ||
|
||
z = Baz(foo={'id': 1}, name='test') | ||
assert z.foo.id == 1 |
24 changes: 24 additions & 0 deletions
24
tests/mypy/outputs/1.0.1/mypy-plugin_ini/plugin_optional_inheritance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
id: Optional[int] | ||
|
||
|
||
class Bar(BaseModel): | ||
foo: Optional[Foo] | ||
|
||
|
||
class Baz(Bar): | ||
name: str | ||
|
||
|
||
b = Bar(foo={'id': 1}) | ||
assert b.foo.id == 1 | ||
# MYPY: error: Item "None" of "Optional[Foo]" has no attribute "id" [union-attr] | ||
|
||
z = Baz(foo={'id': 1}, name='test') | ||
assert z.foo.id == 1 | ||
# MYPY: error: Item "None" of "Optional[Foo]" has no attribute "id" [union-attr] |
24 changes: 24 additions & 0 deletions
24
tests/mypy/outputs/1.0.1/pyproject-plugin_toml/plugin_optional_inheritance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
id: Optional[int] | ||
|
||
|
||
class Bar(BaseModel): | ||
foo: Optional[Foo] | ||
|
||
|
||
class Baz(Bar): | ||
name: str | ||
|
||
|
||
b = Bar(foo={'id': 1}) | ||
assert b.foo.id == 1 | ||
# MYPY: error: Item "None" of "Optional[Foo]" has no attribute "id" [union-attr] | ||
|
||
z = Baz(foo={'id': 1}, name='test') | ||
assert z.foo.id == 1 | ||
# MYPY: error: Item "None" of "Optional[Foo]" has no attribute "id" [union-attr] |
24 changes: 24 additions & 0 deletions
24
tests/mypy/outputs/1.4.1/mypy-plugin_ini/plugin_optional_inheritance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
id: Optional[int] | ||
|
||
|
||
class Bar(BaseModel): | ||
foo: Optional[Foo] | ||
|
||
|
||
class Baz(Bar): | ||
name: str | ||
|
||
|
||
b = Bar(foo={'id': 1}) | ||
assert b.foo.id == 1 | ||
# MYPY: error: Item "None" of "Foo | None" has no attribute "id" [union-attr] | ||
|
||
z = Baz(foo={'id': 1}, name='test') | ||
assert z.foo.id == 1 | ||
# MYPY: error: Item "None" of "Foo | None" has no attribute "id" [union-attr] |
24 changes: 24 additions & 0 deletions
24
tests/mypy/outputs/1.4.1/pyproject-plugin_toml/plugin_optional_inheritance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
id: Optional[int] | ||
|
||
|
||
class Bar(BaseModel): | ||
foo: Optional[Foo] | ||
|
||
|
||
class Baz(Bar): | ||
name: str | ||
|
||
|
||
b = Bar(foo={'id': 1}) | ||
assert b.foo.id == 1 | ||
# MYPY: error: Item "None" of "Foo | None" has no attribute "id" [union-attr] | ||
|
||
z = Baz(foo={'id': 1}, name='test') | ||
assert z.foo.id == 1 | ||
# MYPY: error: Item "None" of "Foo | None" has no attribute "id" [union-attr] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters