-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Handle TypedDict in diff and deps #4510
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -562,3 +562,59 @@ B = Enum('B', 'y') | |
[out] | ||
__main__.B.x | ||
__main__.B.y | ||
|
||
[case testTypedDict] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int, 'y': int}) | ||
p = Point(dict(x=42, y=1337)) | ||
[file next.py] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int, 'y': str}) | ||
p = Point(dict(x=42, y='lurr')) | ||
[builtins fixtures/dict.pyi] | ||
[out] | ||
__main__.Point | ||
__main__.p | ||
|
||
[case testTypedDict2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test also that removing or adding a field triggers a TypedDict type. And test that changing totality triggers the type. |
||
from mypy_extensions import TypedDict | ||
class Point(TypedDict): | ||
x: int | ||
y: int | ||
p = Point(dict(x=42, y=1337)) | ||
[file next.py] | ||
from mypy_extensions import TypedDict | ||
class Point(TypedDict): | ||
x: int | ||
y: str | ||
p = Point(dict(x=42, y='lurr')) | ||
[builtins fixtures/dict.pyi] | ||
[out] | ||
__main__.Point | ||
__main__.p | ||
|
||
[case testTypedDict3] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int, 'y': int}) | ||
p = Point(dict(x=42, y=1337)) | ||
[file next.py] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int}) | ||
p = Point(dict(x=42)) | ||
[builtins fixtures/dict.pyi] | ||
[out] | ||
__main__.Point | ||
__main__.p | ||
|
||
[case testTypedDict4] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int, 'y': int}) | ||
p = Point(dict(x=42, y=1337)) | ||
[file next.py] | ||
from mypy_extensions import TypedDict | ||
Point = TypedDict('Point', {'x': int, 'y': int}, total=False) | ||
p = Point(dict(x=42, y=1337)) | ||
[builtins fixtures/dict.pyi] | ||
[out] | ||
__main__.Point | ||
__main__.p |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,8 @@ MypyFile:1( | |
ImportFrom:1(mypy_extensions, [TypedDict]) | ||
ClassDef:2( | ||
A | ||
BaseTypeExpr( | ||
NameExpr(TypedDict [mypy_extensions.TypedDict])) | ||
BaseType( | ||
typing.Mapping[builtins.str, builtins.str]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A consequence of the semanal changes that replace the TypeInfo with the |
||
ExpressionStmt:3( | ||
StrExpr(foo)) | ||
AssignmentStmt:4( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am mostly in favor of "unification" of
TypedDict
andNamedTuple
, but why can't you just useo.info.replaced.typeddict_type
here? (Then you wouldn't need to changesemanal.py
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced
doesn't get serialized, so the right thing to do seemed to be followingNamedTuple
and actually doing the replacement.