-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[clean strict optional] Use dummy TypeInfo instead of None in Instance.type (and few more fixes) #3285
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
[clean strict optional] Use dummy TypeInfo instead of None in Instance.type (and few more fixes) #3285
Changes from all commits
0829d09
fcd53f3
36c5182
5bd0349
38ec0a6
469d523
a5c0958
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 |
---|---|---|
|
@@ -2208,6 +2208,23 @@ def deserialize(cls, data: JsonDict) -> 'TypeInfo': | |
return ti | ||
|
||
|
||
class FakeInfo(TypeInfo): | ||
# types.py defines a single instance of this class, called types.NOT_READY. | ||
# This instance is used as a temporary placeholder in the process of de-serialization | ||
# of 'Instance' types. The de-serialization happens in two steps: In the first step, | ||
# Instance.type is set to NOT_READY. In the second step (in fixup.py) it is replaced by | ||
# an actual TypeInfo. If you see the assertion error below, then most probably something | ||
# went wrong during the second step and an 'Instance' that raised this error was not fixed. | ||
# Note: | ||
# 'None' is not used as a dummy value for two reasons: | ||
# 1. This will require around 80-100 asserts to make 'mypy --strict-optional mypy' | ||
# pass cleanly. | ||
# 2. If NOT_READY value is accidentally used somewhere, it will be obvious where the value | ||
# is from, whereas a 'None' value could come from anywhere. | ||
def __getattr__(self, attr: str) -> None: | ||
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. @ilevkivskyi @gvanrossum This should probably be 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. In any case 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. OK, but then I suspect that #3281 will come back. So we should at least have a test in place to verify it doesn't. (Because that's the kind of error that's being masked here -- and since in that particular case it was just getting the wrong full name of some type for some error message I'd rather have a poor error than a crash -- our users really don't like crashes. 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. @gvanrossum |
||
raise AssertionError('De-serialization failure: TypeInfo not fixed') | ||
|
||
|
||
class SymbolTableNode: | ||
# Kind of node. Possible values: | ||
# - LDEF: local definition (of any kind) | ||
|
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.
Excellent reasons!