-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Don't interpret arguments with a default of None as Optional #3248
Conversation
It would be much better if this started out as a command-line flag. (Probably global, unless it's really easy to make it per-module.) |
I agree that this would be better as a flag, at least in the next release or two. |
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.
Please make this a flag. (Global if you have to, per-mod if it's easy.)
9b37a71
to
5146ae2
Compare
Updated to use an off-by-default per-module flag. |
I haven't looked in detail at your code yet, but when I tried this, the typeshed tests for Python 2.7 started failing without enabling the new flag. To repro, check out this PR, then
I don't want to post the entire list of errors (too long and boring) but here are the first few and last few:
|
# as unicode instead of bytes. This hack is generally okay, | ||
# because mypy considers str literals to be compatible with | ||
# unicode. | ||
return StrExpr(n.s) |
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.
These changes seem at first unrelated to --no-implicit-optional -- why are they here?
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 made this change in lieu of updating self.pyversion
-> self.options.python_version
because we've asserted that this is a Python 3 or stub file in the constructor (so only one codepath is ever taken here).
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.
Ah, OK. There should be no major version checks in fastparse{,2}.py at all.
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.
(In the light of the bug you fixed, as a follow-up, it seems there should be no major version checks in fastparse2.py, but those in fastparse.py should be kept, since much of that file is still shared with fastparse2.py.)
So I can still repro the issue with typeshed. Can you look into that? |
Yep! I repro'd them too. I was overzealous in removing version checks -- one is actually needed in fastparse.py (see the commit I just pushed which fixes it). |
I tried to use this and realized it only has an effect when But the error that it produces is "Incompatible types in assignment (expression has type None, variable has type ...)". I think it deserves a more specialized error, e.g. "Default for argument XXX is incompatible with its type (expression has type None, argument has type ...)". If you agree, can you file a new issue to track that task? |
Might be worth explicitly adding a note that suggests using |
Should probably be "are not supported with |
* master: (23 commits) Make return type of open() more precise (python#3477) Add test cases that delete a file during incremental checking (python#3461) Parse each format-string component separately (python#3390) Don't warn about returning Any if it is a proper subtype of the return type (python#3473) Add __setattr__ support (python#3451) Remove bundled lib-typing (python#3337) Move version of extensions to post-release (python#3348) Fix None slice bounds with strict-optional (python#3445) Allow NewType subclassing NewType. (python#3465) Add console scripts (python#3074) Fix 'variance' label. Change label for variance section to just 'variance' (python#3429) Better error message for invalid package names passed to mypy (python#3447) Fix last character cut in html-report if file does not end with newline (python#3466) Print pytest output as it happens (python#3463) Add mypy roadmap (python#3460) Add flag to avoid interpreting arguments with a default of None as Optional (python#3248) Add type checking plugin support for functions (python#3299) Mismatch of inferred type and return type note (python#3428) Sync typeshed (python#3449) ...
Fix python/typing#275.
(Likely needs a bit more discussion.)