Enable mypy error codes

This commit is contained in:
Adam Turner 2024-01-13 22:04:59 +00:00
parent 17c1aa76c6
commit 0a76199f99
5 changed files with 15 additions and 6 deletions

View File

@ -141,8 +141,17 @@ show_column_numbers = true
show_error_context = true show_error_context = true
strict_optional = true strict_optional = true
warn_redundant_casts = true warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true warn_unused_ignores = true
disallow_any_generics = true disallow_any_generics = true
extra_checks = true
enable_error_code = [
"type-arg",
"redundant-self",
"truthy-iterable",
"ignore-without-code",
"unused-awaitable",
]
[[tool.mypy.overrides]] [[tool.mypy.overrides]]
module = [ module = [

View File

@ -93,7 +93,7 @@ class Index(ABC):
shortname: str | None = None shortname: str | None = None
def __init__(self, domain: Domain) -> None: def __init__(self, domain: Domain) -> None:
if self.name is None or self.localname is None: if not self.name or self.localname is None:
raise SphinxError('Index subclass %s has no valid name or localname' raise SphinxError('Index subclass %s has no valid name or localname'
% self.__class__.__name__) % self.__class__.__name__)
self.domain = domain self.domain = domain

View File

@ -104,8 +104,8 @@ class PygmentsBridge:
self.formatter = self.latex_formatter self.formatter = self.latex_formatter
self.formatter_args['commandprefix'] = 'PYG' self.formatter_args['commandprefix'] = 'PYG'
def get_style(self, stylename: str) -> Style: def get_style(self, stylename: str) -> type[Style]:
if stylename is None or stylename == 'sphinx': if not stylename or stylename == 'sphinx':
return SphinxStyle return SphinxStyle
elif stylename == 'none': elif stylename == 'none':
return NoneStyle return NoneStyle

View File

@ -47,7 +47,7 @@ class ImageDownloader(BaseImageConverter):
default_priority = 100 default_priority = 100
def match(self, node: nodes.image) -> bool: def match(self, node: nodes.image) -> bool:
if self.app.builder.supported_image_types == []: if not self.app.builder.supported_image_types:
return False return False
if self.app.builder.supported_remote_images: if self.app.builder.supported_remote_images:
return False return False
@ -117,7 +117,7 @@ class DataURIExtractor(BaseImageConverter):
default_priority = 150 default_priority = 150
def match(self, node: nodes.image) -> bool: def match(self, node: nodes.image) -> bool:
if self.app.builder.supported_remote_images == []: if not self.app.builder.supported_remote_images:
return False return False
if self.app.builder.supported_data_uri_images is True: if self.app.builder.supported_data_uri_images is True:
return False return False

View File

@ -220,7 +220,7 @@ def is_translatable(node: Node) -> bool:
return False return False
# <field_name>orphan</field_name> # <field_name>orphan</field_name>
# XXX ignore all metadata (== docinfo) # XXX ignore all metadata (== docinfo)
if isinstance(node, nodes.field_name) and node.children[0] == 'orphan': if isinstance(node, nodes.field_name) and (node.children[0] == 'orphan'):
logger.debug('[i18n] SKIP %r because orphan node: %s', logger.debug('[i18n] SKIP %r because orphan node: %s',
get_full_module_name(node), repr_domxml(node)) get_full_module_name(node), repr_domxml(node))
return False return False