Skip to content

Commit 6d5bf84

Browse files
committed
fix some flake8 lint
1 parent acbed24 commit 6d5bf84

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

mypy/errorcodes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def __str__(self) -> str:
135135
)
136136
UNSAFE_VARIANCE: Final = ErrorCode("unsafe-variance", "Incorrect usages of variance", "General")
137137
UNUSED_IGNORE: Final = ErrorCode("unused-ignore", "Ignore comment is unused", "General")
138-
NO_ERROR_CODE: Final = ErrorCode("no-error-code", "No error code specified in ignore comment", "General")
138+
NO_ERROR_CODE: Final = ErrorCode("no-error-code", "No error code specified in ignore comment",
139+
"General")
139140

140141
# Syntax errors are often blocking.
141142
SYNTAX: Final = ErrorCode("syntax", "Report syntax errors", "General")

mypy/errors.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self,
120120
Optional[ErrorCode]]
121121

122122

123-
def filter_prefix(map: dict[str, list[ErrorInfo]]) -> dict[str, list[ErrorInfo]]:
123+
def filter_prefix(map: Dict[str, List[ErrorInfo]]) -> Dict[str, List[ErrorInfo]]:
124124
result = {file.removeprefix(os.getcwd()): errors for file, errors in map.items()}
125125
for errors in result.values():
126126
for error in errors:
@@ -129,7 +129,7 @@ def filter_prefix(map: dict[str, list[ErrorInfo]]) -> dict[str, list[ErrorInfo]]
129129
return result
130130

131131

132-
def baseline_json_hook(d: dict[str, object]):
132+
def baseline_json_hook(d: Dict[str, object]):
133133
class_ = d.pop(".class", None)
134134
if class_ is None: return d
135135
if class_ == "mypy.errors.ErrorInfo":
@@ -793,13 +793,15 @@ def remove_duplicates(self, errors: List[ErrorTuple]) -> List[ErrorTuple]:
793793

794794
def save_baseline(self, file: Path) -> None:
795795
"""Create/update a file that stores all errors"""
796-
797796
if not file.parent.exists():
798797
file.parent.mkdir()
799798
json.dump(
800799
filter_prefix(self.error_info_map),
801800
file.open("w"),
802-
default=lambda o: {".class": (t := type(o)).__module__ + "." + t.__qualname__} | o.__dict__
801+
default=lambda o: {
802+
**{".class": type(o).__module__ + "." + type(o).__qualname__},
803+
**o.__dict__,
804+
}
803805
)
804806

805807
def load_baseline(self, file: Path) -> None:
@@ -822,7 +824,8 @@ def filter_baseline(self) -> None:
822824
for baseline_error in baseline_errors:
823825
if (
824826
error.line == baseline_error.line and error.code == baseline_error.code
825-
or error.message == baseline_error.message and abs(error.line - baseline_error.line) < 50
827+
or error.message == baseline_error.message and
828+
abs(error.line - baseline_error.line) < 50
826829
):
827830
break
828831
else:

mypy/main.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ def main(script_path: Optional[str],
126126
stdout.flush()
127127

128128
if options.write_baseline:
129-
stdout.write(formatter.style("Baseline successfully written to {}\n".format(options.baseline_file),
130-
"green", bold=True))
129+
stdout.write(
130+
formatter.style("Baseline successfully written to {}\n".format(options.baseline_file),
131+
"green", bold=True))
131132
code = 0
132133

133134
if options.install_types and not options.non_interactive:
@@ -300,7 +301,7 @@ def infer_python_executable(options: Options,
300301

301302

302303
DESCRIPTION: Final = """
303-
Basedmypy is a program that will type check your Python code.
304+
Basedmypy is a program that will type check your Python code.
304305
305306
Based? Based on what?
306307
@@ -516,8 +517,8 @@ def add_invertible_flag(flag: str,
516517
help="Configuration file, must have a [mypy] section "
517518
"(defaults to {})".format(', '.join(defaults.CONFIG_FILES)))
518519
add_invertible_flag('--no-warn-unused-configs', default=True, dest="warn_unused_configs",
519-
help="Don't warn about unused '[mypy-<pattern>]' or '[[tool.mypy.overrides]]' "
520-
"config sections",
520+
help="Don't warn about unused '[mypy-<pattern>]' or "
521+
"'[[tool.mypy.overrides]]' config sections",
521522
group=config_group)
522523

523524
imports_group = parser.add_argument_group(
@@ -575,7 +576,8 @@ def add_invertible_flag(flag: str,
575576
title='Allow dynamic typing',
576577
description="Allow the use of the dynamic 'Any' type under certain conditions.")
577578
disallow_any_group.add_argument(
578-
'--allow-any-unimported', default=True, action='store_false', dest="disallow_any_unimported",
579+
'--allow-any-unimported', default=True, action='store_false',
580+
dest="disallow_any_unimported",
579581
help="Allow Any types resulting from unfollowed imports")
580582
disallow_any_group.add_argument(
581583
'--allow-any-expr', default=True, action='store_false', dest="disallow_any_expr",
@@ -614,7 +616,8 @@ def add_invertible_flag(flag: str,
614616
add_invertible_flag('--no-check-untyped-defs', default=True, dest="check_untyped_defs",
615617
help="Don't type check the interior of functions without type annotations",
616618
group=untyped_group)
617-
add_invertible_flag('--allow-untyped-decorators', default=True, dest="disallow_untyped_decorators",
619+
add_invertible_flag('--allow-untyped-decorators', default=True,
620+
dest="disallow_untyped_decorators",
618621
help="Allow decorating typed functions with untyped decorators",
619622
group=untyped_group)
620623

@@ -647,7 +650,8 @@ def add_invertible_flag(flag: str,
647650
help="Do not warn about unneeded '# type: ignore' comments",
648651
group=lint_group)
649652
add_invertible_flag('--no-warn-no-ignore-code', default=False,
650-
help="Do not warn about '# type: ignore' comments that don't specify the error code",
653+
help="Do not warn about '# type: ignore' comments "
654+
"that don't specify the error code",
651655
group=lint_group)
652656
add_invertible_flag('--no-warn-no-return', dest='warn_no_return', default=True,
653657
help="Do not warn about functions that end without returning",

mypy/message_registry.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ def format(self, *args: object, **kwargs: object) -> "ErrorMessage":
8585
FORMAT_REQUIRES_MAPPING: Final = "Format requires a mapping"
8686
RETURN_TYPE_CANNOT_BE_CONTRAVARIANT: Final = ErrorMessage(
8787
"This usage of this contravariant type variable is unsafe as a return type.\n"
88-
"If this is intentional and you know what you are doing, you can ignore this line with 'unsafe-variance'"
88+
"If this is intentional and you know what you are doing, "
89+
"you can ignore this line with 'unsafe-variance'"
8990
)
9091
FUNCTION_PARAMETER_CANNOT_BE_COVARIANT: Final = ErrorMessage(
9192
"This usage of this covariant type variable is unsafe as an input parameter.\n"
92-
"If this is intentional and you know what you are doing, you can ignore this line with 'unsafe-variance'"
93+
"If this is intentional and you know what you are doing, "
94+
"you can ignore this line with 'unsafe-variance'"
9395
)
9496
INCOMPATIBLE_IMPORT_OF: Final = "Incompatible import of"
9597
FUNCTION_TYPE_EXPECTED: Final = ErrorMessage(

setup.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,34 @@
2424
Basedmypy -- Based Static Typing for Python
2525
===========================================
2626
27-
Add type annotations to your Python programs, and use mypy to type
28-
check them. Mypy is essentially a Python linter on steroids, and it
29-
can catch many programming errors by analyzing your program, without
30-
actually having to run it. Mypy has a powerful type system with
31-
features such as type inference, gradual typing, generics and union
32-
types.
27+
Ever tried to use pythons type system and thought to yourself "This doesn't seem based".
28+
29+
Well fret no longer as basedmypy got you covered!
30+
31+
Baseline
32+
--------
33+
34+
Basedmypy has baseline, baseline is based! It allows you to adopt new features from basedmypy
35+
without the burden of fixing up every usage, just save all current errors to the baseline
36+
file and deal with them later.
37+
38+
.. code-block:: python
39+
40+
def foo(a):
41+
print(a)
42+
43+
.. code-block:: bash
44+
45+
> mypy .
46+
error: missing typehints !!!!!
47+
Epic fail bro!
48+
49+
> mypy --write-baseline .
50+
error: missing typehints
51+
Baseline successfully saved!
52+
53+
> mypy .
54+
Looks good to me, no errors!
3355
'''.lstrip()
3456

3557

@@ -203,7 +225,7 @@ def run(self):
203225
python_requires=">=3.6",
204226
include_package_data=True,
205227
project_urls={
206-
'News': 'http://mypy-lang.org/news.html',
228+
'News': 'https://github.com/KotlinIsland/basedmypy/releases',
207229
'Documentation': 'https://mypy.readthedocs.io/en/stable/introduction.html',
208230
'Repository': 'https://github.com/KotlinIsland/basedmypy',
209231
},

0 commit comments

Comments
 (0)