🎨 Convert type comments into Python type hints (#4575)

* com2ann: Convert type comments into Python type hints - again

* Make modifications based on code review
This commit is contained in:
Christian Clauss authored and GitHub committed 2022-08-01 09:23:56 +02:00
1 parent 936af41d0e
commit 8680ca4495
4 files changed
+11 -21

No files matched your search

+3 -7
View File
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = "The MIT License <http://opensource.org/licenses/MIT>"
@@ -20,9 +19,7 @@ from pygments.filters import VisibleWhitespaceFilter, ErrorToken
from pygments.lexers.python import PythonConsoleLexer
from pygments.util import ClassNotFound
if False:
# For type annotation
from typing import Any, Dict, List, Tuple # NOQA
from typing import Any
def _merge_dict(a, b):
@@ -75,8 +72,7 @@ class CodeBlockExt(CodeBlock):
option_spec = _merge_dict(CodeBlock.option_spec, {"whitespace": directives.flag})
def run(self):
# type: () -> List[nodes.Node]
def run(self) -> list[nodes.Node]:
# get result from parent implementation
code_block = CodeBlock.run(self)
+4 -9
View File
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import annotations
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = "The MIT License <http://opensource.org/licenses/MIT>"
@@ -21,16 +20,13 @@ from sphinx.directives.code import (
)
from sphinx.util.nodes import set_source_info
if False:
# For type annotation
from typing import Any, List # NOQA
from typing import Any
cache = {}
class OnlineIncludeReader(LiteralIncludeReader):
def read_file(self, filename, location=None):
# type: (unicode, Any) -> List[unicode]
def read_file(self, filename: str, location: Any = None) -> list[str]:
global cache
try:
@@ -56,8 +52,7 @@ class OnlineIncludeReader(LiteralIncludeReader):
class OnlineIncludeDirective(LiteralInclude):
def run(self):
# type: () -> List[nodes.Node]
def run(self) -> list[nodes.Node]:
document = self.state.document
if not document.settings.file_insertion_enabled:
return [
+2 -2
View File
@@ -164,7 +164,7 @@ class StorageInterface:
:param string path: the path of the new folder
:param bool ignore_existing: if set to True, no error will be raised if the folder to be added already exists
:param unicode display: display name of the folder
:param str display: display name of the folder
:return: the sanitized name of the new folder to be used for future references to the folder
"""
raise NotImplementedError()
@@ -220,7 +220,7 @@ class StorageInterface:
:param list links: any links to add with the file
:param bool allow_overwrite: if set to True no error will be raised if the file already exists and the existing file
and its metadata will just be silently overwritten
:param unicode display: display name of the file
:param str display: display name of the file
:return: the sanitized name of the file to be used for future references to it
"""
raise NotImplementedError()
+2 -3
View File
@@ -77,7 +77,7 @@ def to_unicode(
s_or_u: Union[str, bytes], encoding: str = "utf-8", errors: str = "strict"
) -> str:
"""
Make sure ``s_or_u`` is a unicode string (str).
Make sure ``s_or_u`` is a string (str).
Arguments:
s_or_u (str or bytes): The value to convert
@@ -202,7 +202,6 @@ def warning_factory(warning_type):
"__dict__",
"__doc__",
"__str__",
"__unicode__",
"__repr__",
"__getattribute__",
"__setattr__",
@@ -1611,7 +1610,7 @@ class CaseInsensitiveSet(Set):
"""
Basic case insensitive set
Any str or unicode values will be stored and compared in lower case. Other value types are left as-is.
Any str values will be stored and compared in lower case. Other value types are left as-is.
"""
def __init__(self, *args):