Skip to content

Commit

Permalink
add strict overrides flag
Browse files Browse the repository at this point in the history
Summary:
This diff adds a flag that will eventually be used to toggle the PEP698 strict override checks added in D59398364. Currently it is unused, I'll hook it up and add a test in the next diff.

This is a lot of files to modify to add a single flag, and we definitely need to change this if we want to eventually add a flag for tuning each type of error.

I guess there isn't a way to spread ocaml record types into each other, so maybe in the future these could be composed somehow w/ a shared nested record that contains a boolean flag for each error code?

Reviewed By: kinto0

Differential Revision: D60078685

fbshipit-source-id: ae3aeec797dc4b255cd4b5728a4d907cd5618dd4
  • Loading branch information
yangdanny97 authored and facebook-github-bot committed Jul 23, 2024
1 parent 2391822 commit 3f1813a
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/backend_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class BaseArguments:

debug: bool = False
enable_readonly_analysis: Optional[bool] = None
enable_strict_override_check: Optional[bool] = None
enable_unawaited_awaitable_analysis: Optional[bool] = None
excludes: Sequence[str] = dataclasses.field(default_factory=list)
extensions: Sequence[str] = dataclasses.field(default_factory=list)
Expand Down Expand Up @@ -218,6 +219,11 @@ def serialize(self) -> Dict[str, Any]:
if self.enable_readonly_analysis is not None
else {}
),
**(
{"enable_strict_override_check": self.enable_strict_override_check}
if self.enable_strict_override_check is not None
else {}
),
**(
{
"enable_unawaited_awaitable_analysis": (
Expand Down
1 change: 1 addition & 0 deletions client/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def create_check_arguments(
checked_directory_blocklist=(configuration.get_ignore_all_errors()),
debug=check_arguments.debug,
enable_readonly_analysis=configuration.get_enable_readonly_analysis(),
enable_strict_override_check=configuration.get_enable_strict_override_check(),
enable_unawaited_awaitable_analysis=(
configuration.get_enable_unawaited_awaitable_analysis()
),
Expand Down
1 change: 1 addition & 0 deletions client/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def create_server_arguments(
checked_directory_blocklist=(configuration.get_ignore_all_errors()),
debug=start_arguments.debug,
enable_readonly_analysis=configuration.get_enable_readonly_analysis(),
enable_strict_override_check=configuration.get_enable_strict_override_check(),
enable_unawaited_awaitable_analysis=(
configuration.get_enable_unawaited_awaitable_analysis()
),
Expand Down
11 changes: 11 additions & 0 deletions client/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class PartialConfiguration:
)
dot_pyre_directory: Optional[Path] = None
enable_readonly_analysis: Optional[bool] = None
enable_strict_override_check: Optional[bool] = None
enable_unawaited_awaitable_analysis: Optional[bool] = None
excludes: Sequence[str] = field(
default_factory=list,
Expand Down Expand Up @@ -433,6 +434,9 @@ def create_search_paths(
enable_readonly_analysis=ensure_option_type(
configuration_json, "enable_readonly_analysis", bool
),
enable_strict_override_check=ensure_option_type(
configuration_json, "enable_strict_override_check", bool
),
enable_unawaited_awaitable_analysis=ensure_option_type(
configuration_json, "enable_unawaited_awaitable_analysis", bool
),
Expand Down Expand Up @@ -580,6 +584,7 @@ class Configuration:
only_check_paths: Sequence[str] = field(default_factory=list)
dot_pyre_directory: Optional[Path] = None
enable_readonly_analysis: Optional[bool] = None
enable_strict_override_check: Optional[bool] = None
enable_unawaited_awaitable_analysis: Optional[bool] = None
excludes: Sequence[str] = field(default_factory=list)
extensions: Sequence[extension.Element] = field(default_factory=list)
Expand Down Expand Up @@ -636,6 +641,7 @@ def from_partial_configuration(
for path in only_check_paths
],
enable_readonly_analysis=partial_configuration.enable_readonly_analysis,
enable_strict_override_check=partial_configuration.enable_strict_override_check,
enable_unawaited_awaitable_analysis=(
partial_configuration.enable_unawaited_awaitable_analysis
),
Expand Down Expand Up @@ -726,6 +732,11 @@ def to_json(self) -> Dict[str, object]:
if self.enable_readonly_analysis is not None
else {}
),
**(
{"enable_strict_override_check": self.enable_strict_override_check}
if self.enable_strict_override_check is not None
else {}
),
**(
{
"enable_unawaited_awaitable_analysis": (
Expand Down
22 changes: 22 additions & 0 deletions client/configuration/tests/configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_create_from_command_arguments(self) -> None:
self.assertEqual(configuration.number_of_workers, 43)
self.assertEqual(configuration.use_buck2, True)
self.assertEqual(configuration.enable_readonly_analysis, None)
self.assertEqual(configuration.enable_strict_override_check, None)
self.assertEqual(configuration.enable_unawaited_awaitable_analysis, True)
self.assertEqual(configuration.include_suppressed_errors, True)

Expand Down Expand Up @@ -432,6 +433,18 @@ def test_create_from_string_success(self) -> None:
PartialConfiguration.from_string(json.dumps({})).enable_readonly_analysis,
None,
)
self.assertEqual(
PartialConfiguration.from_string(
json.dumps({"enable_strict_override_check": True})
).enable_strict_override_check,
True,
)
self.assertEqual(
PartialConfiguration.from_string(
json.dumps({})
).enable_strict_override_check,
None,
)
self.assertEqual(
PartialConfiguration.from_string(
json.dumps({"enable_unawaited_awaitable_analysis": True})
Expand Down Expand Up @@ -479,6 +492,7 @@ def assert_raises(content: str) -> None:
assert_raises(json.dumps({"only_check_paths": "abc"}))
assert_raises(json.dumps({"dot_pyre_directory": {}}))
assert_raises(json.dumps({"enable_readonly_analysis": 42}))
assert_raises(json.dumps({"enable_strict_override_check": 42}))
assert_raises(json.dumps({"enable_unawaited_awaitable_analysis": 42}))
assert_raises(json.dumps({"exclude": 42}))
assert_raises(json.dumps({"extensions": 42}))
Expand Down Expand Up @@ -587,6 +601,12 @@ def test_expand_relative_paths(self) -> None:
.enable_readonly_analysis,
True,
)
self.assertEqual(
PartialConfiguration(enable_strict_override_check=True)
.expand_relative_paths("bar")
.enable_strict_override_check,
True,
)
self.assertEqual(
PartialConfiguration(enable_unawaited_awaitable_analysis=True)
.expand_relative_paths("bar")
Expand Down Expand Up @@ -629,6 +649,7 @@ def test_from_partial_configuration(self) -> None:
only_check_paths=["//foo"],
dot_pyre_directory=None,
enable_readonly_analysis=True,
enable_strict_override_check=True,
enable_unawaited_awaitable_analysis=True,
excludes=["exclude"],
extensions=[ExtensionElement(".ext", False)],
Expand Down Expand Up @@ -663,6 +684,7 @@ def test_from_partial_configuration(self) -> None:
self.assertListEqual(list(configuration.only_check_paths), ["root/foo"])
self.assertEqual(configuration.dot_pyre_directory, None)
self.assertEqual(configuration.enable_readonly_analysis, True)
self.assertEqual(configuration.enable_strict_override_check, True)
self.assertEqual(configuration.enable_unawaited_awaitable_analysis, True)
self.assertListEqual(list(configuration.excludes), ["exclude"])
self.assertEqual(configuration.extensions, [ExtensionElement(".ext", False)])
Expand Down
7 changes: 7 additions & 0 deletions client/frontend_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def get_project_identifier(self) -> str:
def get_enable_readonly_analysis(self) -> Optional[bool]:
raise NotImplementedError()

@abc.abstractmethod
def get_enable_strict_override_check(self) -> Optional[bool]:
raise NotImplementedError()

@abc.abstractmethod
def get_enable_unawaited_awaitable_analysis(self) -> Optional[bool]:
raise NotImplementedError()
Expand Down Expand Up @@ -395,6 +399,9 @@ def get_taint_models_path(self) -> List[str]:
def get_enable_readonly_analysis(self) -> Optional[bool]:
return self.configuration.enable_readonly_analysis

def get_enable_strict_override_check(self) -> Optional[bool]:
return self.configuration.enable_strict_override_check

def get_enable_unawaited_awaitable_analysis(self) -> Optional[bool]:
return self.configuration.enable_unawaited_awaitable_analysis

Expand Down
3 changes: 3 additions & 0 deletions source/analysis/environmentControls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module TypeCheckControls = struct
include_type_errors: bool;
include_local_annotations: bool;
include_readonly_errors: bool;
include_strict_override_errors: bool;
include_unawaited_awaitable_errors: bool;
debug: bool;
include_suppressed_errors: bool;
Expand All @@ -81,6 +82,7 @@ let type_check_controls
store_type_errors;
store_type_check_resolution;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
_;
Expand All @@ -95,6 +97,7 @@ let type_check_controls
include_type_errors = store_type_errors;
include_local_annotations = store_type_check_resolution;
include_readonly_errors = enable_readonly_analysis;
include_strict_override_errors = enable_strict_override_check;
include_unawaited_awaitable_errors = enable_unawaited_awaitable_analysis;
include_suppressed_errors;
no_validation_on_class_lookup_failure;
Expand Down
1 change: 1 addition & 0 deletions source/analysis/environmentControls.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module TypeCheckControls : sig
include_type_errors: bool;
include_local_annotations: bool;
include_readonly_errors: bool;
include_strict_override_errors: bool;
include_unawaited_awaitable_errors: bool;
debug: bool;
include_suppressed_errors: bool;
Expand Down
1 change: 1 addition & 0 deletions source/buck_command/checkCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let create_environment_controls ~root ~python_version () =
~python_version
~enable_type_comments:true
~enable_readonly_analysis:false
~enable_strict_override_check:false
~enable_unawaited_awaitable_analysis:true
~include_suppressed_errors:false
~use_errpy_parser:false
Expand Down
2 changes: 2 additions & 0 deletions source/command/analyzeCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ module AnalyzeConfiguration = struct
number_of_workers;
long_lived_workers;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
shared_memory =
Expand Down Expand Up @@ -302,6 +303,7 @@ module AnalyzeConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
2 changes: 2 additions & 0 deletions source/command/checkCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module CheckConfiguration = struct
number_of_workers;
long_lived_workers;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
shared_memory =
Expand Down Expand Up @@ -112,6 +113,7 @@ module CheckConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
2 changes: 2 additions & 0 deletions source/command/codeNavigationCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module CodeNavigationConfiguration = struct
number_of_workers;
long_lived_workers;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
shared_memory =
Expand Down Expand Up @@ -105,6 +106,7 @@ module CodeNavigationConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
8 changes: 8 additions & 0 deletions source/command/commandStartup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module BaseConfiguration = struct
profiling_output: string option;
memory_profiling_output: string option;
enable_readonly_analysis: bool;
enable_strict_override_check: bool;
enable_unawaited_awaitable_analysis: bool;
include_suppressed_errors: bool;
(* Parser controls *)
Expand Down Expand Up @@ -114,6 +115,12 @@ module BaseConfiguration = struct
"enable_readonly_analysis"
~default:Configuration.Analysis.default_enable_readonly_analysis
in
let enable_strict_override_check =
json
|> bool_member
"enable_strict_override_check"
~default:Configuration.Analysis.default_enable_strict_override_check
in
let enable_unawaited_awaitable_analysis =
json
|> bool_member
Expand Down Expand Up @@ -152,6 +159,7 @@ module BaseConfiguration = struct
profiling_output;
memory_profiling_output;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
use_errpy_parser;
Expand Down
2 changes: 2 additions & 0 deletions source/command/inferCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module InferConfiguration = struct
number_of_workers;
long_lived_workers;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
shared_memory =
Expand Down Expand Up @@ -102,6 +103,7 @@ module InferConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
2 changes: 2 additions & 0 deletions source/command/noDaemonQueryCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module QueryConfiguration = struct
shared_memory =
{ Configuration.SharedMemory.heap_size; dependency_table_power; hash_table_power };
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
remote_logging = _;
Expand Down Expand Up @@ -107,6 +108,7 @@ module QueryConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
2 changes: 2 additions & 0 deletions source/command/serverCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ module ServerConfiguration = struct
number_of_workers;
long_lived_workers;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
shared_memory =
Expand Down Expand Up @@ -179,6 +180,7 @@ module ServerConfiguration = struct
~enable_type_comments
~source_paths:(Configuration.SourcePaths.to_search_paths source_paths)
~enable_readonly_analysis
~enable_strict_override_check
~enable_unawaited_awaitable_analysis
~include_suppressed_errors
~use_errpy_parser
Expand Down
1 change: 1 addition & 0 deletions source/command/test/baseConfigurationTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let dummy_base_configuration =
checked_directory_allowlist = [];
checked_directory_blocklist = [];
enable_readonly_analysis = false;
enable_strict_override_check = false;
enable_unawaited_awaitable_analysis = false;
extensions = [];
log_path = PyrePath.create_absolute "/log";
Expand Down
5 changes: 5 additions & 0 deletions source/configuration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ module Analysis = struct

let default_enable_readonly_analysis = false

let default_enable_strict_override_check = false

let default_enable_unawaited_awaitable_analysis = false

let default_include_suppressed_errors = false
Expand Down Expand Up @@ -392,6 +394,7 @@ module Analysis = struct
shared_memory: shared_memory;
enable_type_comments: bool;
enable_readonly_analysis: bool;
enable_strict_override_check: bool;
enable_unawaited_awaitable_analysis: bool;
include_suppressed_errors: bool;
use_errpy_parser: bool;
Expand Down Expand Up @@ -424,6 +427,7 @@ module Analysis = struct
?(shared_memory_hash_table_power = default_shared_memory_hash_table_power)
?(enable_type_comments = true)
?(enable_readonly_analysis = default_enable_readonly_analysis)
?(enable_strict_override_check = default_enable_strict_override_check)
?(enable_unawaited_awaitable_analysis = default_enable_unawaited_awaitable_analysis)
?(include_suppressed_errors = default_include_suppressed_errors)
?(use_errpy_parser = default_use_errpy_parser)
Expand Down Expand Up @@ -479,6 +483,7 @@ module Analysis = struct
};
enable_type_comments;
enable_readonly_analysis;
enable_strict_override_check;
enable_unawaited_awaitable_analysis;
include_suppressed_errors;
use_errpy_parser;
Expand Down
4 changes: 4 additions & 0 deletions source/configuration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ module Analysis : sig

val default_enable_readonly_analysis : bool

val default_enable_strict_override_check : bool

val default_enable_unawaited_awaitable_analysis : bool

val default_include_suppressed_errors : bool
Expand Down Expand Up @@ -143,6 +145,7 @@ module Analysis : sig
shared_memory: shared_memory;
enable_type_comments: bool;
enable_readonly_analysis: bool;
enable_strict_override_check: bool;
enable_unawaited_awaitable_analysis: bool;
include_suppressed_errors: bool;
use_errpy_parser: bool;
Expand Down Expand Up @@ -174,6 +177,7 @@ module Analysis : sig
?shared_memory_hash_table_power:int ->
?enable_type_comments:bool ->
?enable_readonly_analysis:bool ->
?enable_strict_override_check:bool ->
?enable_unawaited_awaitable_analysis:bool ->
?include_suppressed_errors:bool ->
?use_errpy_parser:bool ->
Expand Down
Loading

0 comments on commit 3f1813a

Please sign in to comment.