Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.3k
[docs] Include a real listing of the flags strict enables in the online documentation#19062
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fb25fe4
failed attempt, very regex-heavy
wyattscarpenter e5e45e5
ok I mean it works now but it doubles up insertions
wyattscarpenter 13787f8
works perfectly
wyattscarpenter f9e20e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9de7d65
get the strict flags another way, to make all the tests pass
wyattscarpenter 80dc22d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0bd84f9
generate the strict list in the build dir, so there won't be any funk…
wyattscarpenter 6f47aee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 18a695e
um, I meant srcdir. Sure.
wyattscarpenter 24f29bc
bruh
wyattscarpenter d3fb269
refactor out define_options
wyattscarpenter c07f095
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3ed2088
my arguments were in the wrong order
wyattscarpenter 5a6ad43
Move the start of the list to the generation code
wyattscarpenter b6b3863
remove syntax that causes annoying error message during generation
wyattscarpenter 5c16af0
add comment about autogeneration
wyattscarpenter ef52262
theoreticaly ==> theoretically
wyattscarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,16 +11,37 @@ | ||
| from sphinx.builders.html import StandaloneHTMLBuilder | ||
| from sphinx.environment import BuildEnvironment | ||
| from mypy.main import define_options | ||
| class MypyHTMLBuilder(StandaloneHTMLBuilder): | ||
| strict_file: Path | ||
| def __init__(self, app: Sphinx, env: BuildEnvironment) -> None: | ||
| super().__init__(app, env) | ||
| self._ref_to_doc = {} | ||
| self.strict_file = Path(self.srcdir) / "strict_list.rst" | ||
| self._add_strict_list() | ||
| def write_doc(self, docname: str, doctree: document) -> None: | ||
| super().write_doc(docname, doctree) | ||
| self._ref_to_doc.update({_id: docname for _id in doctree.ids}) | ||
| def _add_strict_list(self) -> None: | ||
| strict_flags: list[str] | ||
wyattscarpenter marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| _, strict_flags, _ = define_options() | ||
| strict_part = ", ".join(f":option:`{s} <mypy {s}>`" for s in strict_flags) | ||
| if ( | ||
| not strict_part | ||
| or strict_part.isspace() | ||
| or len(strict_part) < 20 | ||
| or len(strict_part) > 2000 | ||
| ): | ||
| raise ValueError(f"{strict_part=}, which doesn't look right (by a simple heuristic).") | ||
| self.strict_file.write_text( | ||
| "For this version of mypy, the list of flags enabled by strict is: " + strict_part | ||
| ) | ||
| def _verify_error_codes(self) -> None: | ||
| from mypy.errorcodes import error_codes | ||
| @@ -55,6 +76,7 @@ def _write_ref_redirector(self) -> None: | ||
| def finish(self) -> None: | ||
| super().finish() | ||
| self._write_ref_redirector() | ||
| self.strict_file.unlink() | ||
| def setup(app: Sphinx) -> dict[str, Any]: | ||
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 |
|---|---|---|
| @@ -462,24 +462,18 @@ def __call__( | ||
| parser.exit() | ||
| def process_options( | ||
| args: list[str], | ||
| stdout: TextIO | None = None, | ||
| stderr: TextIO | None = None, | ||
| require_targets: bool = True, | ||
| server_options: bool = False, | ||
| fscache: FileSystemCache | None = None, | ||
| def define_options( | ||
| program: str = "mypy", | ||
| header: str = HEADER, | ||
| ) -> tuple[list[BuildSource], Options]: | ||
| """Parse command line arguments. | ||
| If a FileSystemCache is passed in, and package_root options are given, | ||
| call fscache.set_package_root() to set the cache's package root. | ||
| """ | ||
| stdout = stdout or sys.stdout | ||
| stderr = stderr or sys.stderr | ||
| stdout: TextIO = sys.stdout, | ||
| stderr: TextIO = sys.stderr, | ||
| server_options: bool = False, | ||
| ) -> tuple[CapturableArgumentParser, list[str], list[tuple[str, bool]]]: | ||
| """Define the options in the parser (by calling a bunch of methods that express/build our desired command-line flags). | ||
| Returns a tuple of: | ||
| a parser object, that can parse command line arguments to mypy (expected consumer: main's process_options), | ||
| a list of what flags are strict (expected consumer: docs' html_builder's _add_strict_list), | ||
| strict_flag_assignments (expected consumer: main's process_options).""" | ||
| parser = CapturableArgumentParser( | ||
| prog=program, | ||
| usage=header, | ||
| @@ -1321,6 +1315,32 @@ def add_invertible_flag( | ||
| dest="special-opts:files", | ||
| help="Type-check given files or directories", | ||
| ) | ||
| return parser, strict_flag_names, strict_flag_assignments | ||
| def process_options( | ||
wyattscarpenter marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| args: list[str], | ||
| stdout: TextIO | None = None, | ||
| stderr: TextIO | None = None, | ||
| require_targets: bool = True, | ||
| server_options: bool = False, | ||
| fscache: FileSystemCache | None = None, | ||
| program: str = "mypy", | ||
| header: str = HEADER, | ||
| ) -> tuple[list[BuildSource], Options]: | ||
| """Parse command line arguments. | ||
| If a FileSystemCache is passed in, and package_root options are given, | ||
| call fscache.set_package_root() to set the cache's package root. | ||
| Returns a tuple of: a list of source files, an Options collected from flags. | ||
| """ | ||
| stdout = stdout if stdout is not None else sys.stdout | ||
| stderr = stderr if stderr is not None else sys.stderr | ||
| parser, _, strict_flag_assignments = define_options( | ||
| program, header, stdout, stderr, server_options | ||
| ) | ||
| # Parse arguments once into a dummy namespace so we can get the | ||
| # filename for the config file and know if the user requested all strict options. | ||
| @@ -1502,11 +1522,9 @@ def set_strict_flags() -> None: | ||
| targets.extend(p_targets) | ||
| for m in special_opts.modules: | ||
| targets.append(BuildSource(None, m, None)) | ||
| return targets, options | ||
| elif special_opts.command: | ||
| options.build_type = BuildType.PROGRAM_TEXT | ||
| targets = [BuildSource(None, None, "\n".join(special_opts.command))] | ||
| return targets, options | ||
| else: | ||
| try: | ||
| targets = create_source_list(special_opts.files, options, fscache) | ||
| @@ -1515,7 +1533,7 @@ def set_strict_flags() -> None: | ||
| # exceptions of different types. | ||
| except InvalidSourceList as e2: | ||
| fail(str(e2), stderr, options) | ||
| return targets, options | ||
| return targets, options | ||
| def process_package_roots( | ||
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.
Uh oh!
There was an error while loading. Please reload this page.