-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NoneType handling for str.format() with specifiers #18952
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
Open
ChristinaTrinh
wants to merge
18
commits into
python:master
Choose a base branch
from
VallinZ:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3fe1aa7
Check for None type in format call
VyZhu 4180b55
Add check for alignment specifier on none
VyZhu 49d8fbf
Fix alignment specifier check to be more dynamic
VyZhu c5d0b71
Move alignment check to special check function
VyZhu 31542a1
Added unit tests to check for Error Message for None argument and als…
ChristinaTrinh 30665c0
Merge pull request #1 from VallinZ/unitTest
ChristinaTrinh feda1d3
Attempt to recognize no __format__ functions must result in error
ChristinaTrinh 5c4e701
Merge branch 'master' of https://github.com/VallinZ/mypy into unitTest
ChristinaTrinh 2286f46
Deleted commented out code
ChristinaTrinh 8b94be8
Remove print for test
VyZhu d4f70fb
Fix isinstance call with get_property_type
VyZhu e3d002e
Fix lint for alignment specifier on none
VyZhu c536cab
Merge pull request #3 from VallinZ/AddAlignmentSpecifierLogic
VallinZ 693486e
Format changed by Linter
ChristinaTrinh cfc6b17
Fix merge conflicts
ChristinaTrinh c979af9
Extend check for format string specifiers and added more unit tests
ChristinaTrinh d46f562
Fix lint error
ChristinaTrinh 35cf276
Merge pull request #5 from VallinZ/AddAlignmentSpecifierLogic
ChristinaTrinh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 add a few more tests - at least with f-strings, with conversion (e.g.
"{!s:>5}".format(None)
is allowed) and with dynamic spec (f"{None:{foo}}"
is also valid,foo
may be an empty string).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'm looking at the case of
which python throws an error but the current implementation does not catch it.
I look into the callExp of this case, it return:
Is there a way to see what value foo represent in MyPy? My understanding is that MyPy is a static tool, so it doesn't have the value of foo. So, technically, there is no way to check this case? So, would it be an option we just raise an warning that there might be an error rather saying that this is an error?
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.
no, false positives should be avoided at all costs in
mypy
. If we can't statically prove that some code is invalid,mypy
should be green.There are
Literal
types andInstance.last_known_value
field, representing the literal vale if we know it. However, we accept any dynamic specifiers everywhere else, so I think this should be deferred to a separate PR if you consider it important enough. For now I'd suggest just ignoring any dynamic spec components; formatting with dynamic alignment specifier should be a very rare case (IMO not worth supporting at all).