-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Replace --disallow-any
flags with separate boolean flags.
#4178
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,24 +119,6 @@ def type_check_only(sources: List[BuildSource], bin_dir: Optional[str], | |
options=options) | ||
|
||
|
||
disallow_any_options = ['unimported', 'expr', 'unannotated', 'decorated', 'explicit', 'generics'] | ||
|
||
|
||
def disallow_any_argument_type(raw_options: str) -> List[str]: | ||
if not raw_options: | ||
# empty string disables all options | ||
return [] | ||
flag_options = [o.strip() for o in raw_options.split(',')] | ||
for option in flag_options: | ||
if option not in disallow_any_options: | ||
formatted_valid_options = ', '.join( | ||
"'{}'".format(o) for o in disallow_any_options) | ||
message = "Invalid '--disallow-any' option '{}' (valid options are: {}).".format( | ||
option, formatted_valid_options) | ||
raise argparse.ArgumentError(None, message) | ||
return flag_options | ||
|
||
|
||
FOOTER = """environment variables: | ||
MYPYPATH additional module search path""" | ||
|
||
|
@@ -272,10 +254,18 @@ def add_invertible_flag(flag: str, | |
help="silently ignore imports of missing modules") | ||
parser.add_argument('--follow-imports', choices=['normal', 'silent', 'skip', 'error'], | ||
default='normal', help="how to treat imports (default normal)") | ||
parser.add_argument('--disallow-any', type=disallow_any_argument_type, default=[], | ||
metavar='{{{}}}'.format(', '.join(disallow_any_options)), | ||
help="disallow various types of Any in a module. Takes a comma-separated " | ||
"list of options (defaults to all options disabled)") | ||
parser.add_argument('--disallow-any-unimported', default=False, action='store_true', | ||
help="disallow usage of types that come from unfollowed imports") | ||
parser.add_argument('--disallow-any-expr', default=False, action='store_true', | ||
help='disallow all expressions in the module that have type Any') | ||
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. I'd drop "in the module" since that's implicit (and you don't say it for the other flags). 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. Yep! |
||
parser.add_argument('--disallow-any-decorated', default=False, action='store_true', | ||
help='disallow functions that have Any in their signature ' | ||
'after decorator transformation') | ||
parser.add_argument('--disallow-any-explicit', default=False, action='store_true', | ||
help='disallow explicit Any in type positions') | ||
parser.add_argument('--disallow-any-generics', default=False, action='store_true', | ||
help='disallow usage of generic types that do not specify explicit ' | ||
'type parameters') | ||
add_invertible_flag('--disallow-untyped-calls', default=False, strict_flag=True, | ||
help="disallow calling functions without type annotations" | ||
" from functions with type annotations") | ||
|
@@ -364,6 +354,8 @@ def add_invertible_flag(flag: str, | |
# --dump-graph will dump the contents of the graph of SCCs and exit. | ||
parser.add_argument('--dump-graph', action='store_true', help=argparse.SUPPRESS) | ||
# deprecated options | ||
parser.add_argument('--disallow-any', dest='special-opts:disallow_any', | ||
help=argparse.SUPPRESS) | ||
add_invertible_flag('--strict-boolean', default=False, | ||
help=argparse.SUPPRESS) | ||
parser.add_argument('-f', '--dirty-stubs', action='store_true', | ||
|
@@ -438,6 +430,9 @@ def add_invertible_flag(flag: str, | |
) | ||
|
||
# Process deprecated options | ||
if special_opts.disallow_any: | ||
print("--disallow-any option was split up into multiple flags. " | ||
"See http://mypy.readthedocs.io/en/latest/command_line.html#disallow-any-flags") | ||
if options.strict_boolean: | ||
print("Warning: --strict-boolean is deprecated; " | ||
"see https://github.com/python/mypy/issues/3195", file=sys.stderr) | ||
|
@@ -462,9 +457,6 @@ def add_invertible_flag(flag: str, | |
print("Warning: --no-fast-parser no longer has any effect. The fast parser " | ||
"is now mypy's default and only parser.") | ||
|
||
if 'unannotated' in options.disallow_any: | ||
options.disallow_untyped_defs = True | ||
|
||
# Check for invalid argument combinations. | ||
if require_targets: | ||
code_methods = sum(bool(c) for c in [special_opts.modules, | ||
|
@@ -652,7 +644,6 @@ def get_init_file(dir: str) -> Optional[str]: | |
'custom_typeshed_dir': str, | ||
'mypy_path': lambda s: [p.strip() for p in re.split('[,:]', s)], | ||
'junit_xml': str, | ||
'disallow_any': disallow_any_argument_type, | ||
# These two are for backwards compatibility | ||
'silent_imports': bool, | ||
'almost_silent': bool, | ||
|
@@ -770,14 +761,6 @@ def parse_section(prefix: str, template: Options, | |
except ValueError as err: | ||
print("%s: %s: %s" % (prefix, key, err), file=sys.stderr) | ||
continue | ||
if key == 'disallow_any': | ||
# "disallow_any = " should disable all disallow_any options, including untyped defs, | ||
# given in a more general config. | ||
if not v: | ||
results['disallow_untyped_defs'] = False | ||
# If "unannotated" is explicitly given, turn on disallow_untyped_defs. | ||
elif 'unannotated' in v: | ||
results['disallow_untyped_defs'] = True | ||
if key == 'silent_imports': | ||
print("%s: silent_imports has been replaced by " | ||
"ignore_missing_imports=True; follow_imports=skip" % prefix, file=sys.stderr) | ||
|
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
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
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
Oops, something went wrong.
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.
Maybe "disallow Any types resulting from unfollowed imports" ?
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.
Yep, this seems reasonable! Done!