Update syntax to Python3.7+.

This commit is contained in:
Hasan Ramezani 2021-12-25 21:25:42 +01:00
parent 5599c5ad45
commit 3d7cd77017
No known key found for this signature in database
GPG Key ID: 36462AEA74DF3539
8 changed files with 11 additions and 33 deletions

View File

@ -32,12 +32,12 @@ repos:
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py36-plus]
args: ['--application-directories=.:src', --py37-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0
hooks:

View File

@ -84,14 +84,14 @@ It is also possible to skip the whole module using
If you wish to skip something conditionally then you can use ``skipif`` instead.
Here is an example of marking a test function to be skipped
when run on an interpreter earlier than Python3.6:
when run on an interpreter earlier than Python3.10:
.. code-block:: python
import sys
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_function():
...

View File

@ -293,9 +293,8 @@ def _write_pyc_fp(
# import. However, there's little reason to deviate.
fp.write(importlib.util.MAGIC_NUMBER)
# https://www.python.org/dev/peps/pep-0552/
if sys.version_info >= (3, 7):
flags = b"\x00\x00\x00\x00"
fp.write(flags)
flags = b"\x00\x00\x00\x00"
fp.write(flags)
# as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
mtime = int(source_stat.st_mtime) & 0xFFFFFFFF
size = source_stat.st_size & 0xFFFFFFFF

View File

@ -4,7 +4,7 @@ import functools
import inspect
import os
import sys
from contextlib import contextmanager
from contextlib import nullcontext as nullcontext # noqa: F401
from inspect import Parameter
from inspect import signature
from pathlib import Path
@ -186,16 +186,6 @@ def getfuncargnames(
return arg_names
if sys.version_info < (3, 7):
@contextmanager
def nullcontext():
yield
else:
from contextlib import nullcontext as nullcontext # noqa: F401
def get_default_arg_names(function: Callable[..., Any]) -> Tuple[str, ...]:
# Note: this code intentionally mirrors the code at the beginning of
# getfuncargnames, to get the arguments which were excluded from its result

View File

@ -3,7 +3,6 @@ import io
import logging
import os
import re
import sys
from contextlib import contextmanager
from io import StringIO
from pathlib import Path
@ -628,16 +627,7 @@ class LoggingPlugin:
# https://github.com/python/mypy/issues/11193
stream: io.TextIOWrapper = fpath.open(mode="w", encoding="UTF-8") # type: ignore[assignment]
if sys.version_info >= (3, 7):
old_stream = self.log_file_handler.setStream(stream)
else:
old_stream = self.log_file_handler.stream
self.log_file_handler.acquire()
try:
self.log_file_handler.flush()
self.log_file_handler.stream = stream
finally:
self.log_file_handler.release()
old_stream = self.log_file_handler.setStream(stream)
if old_stream:
old_stream.close()

View File

@ -128,7 +128,7 @@ class LsofFdLeakChecker:
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=True,
universal_newlines=True,
text=True,
).stdout
def isopen(line: str) -> bool:

View File

@ -913,8 +913,7 @@ class TestPDB:
class TestDebuggingBreakpoints:
def test_supports_breakpoint_module_global(self) -> None:
"""Test that supports breakpoint global marks on Python 3.7+."""
if sys.version_info >= (3, 7):
assert SUPPORTS_BREAKPOINT_BUILTIN is True
assert SUPPORTS_BREAKPOINT_BUILTIN is True
@pytest.mark.skipif(
not SUPPORTS_BREAKPOINT_BUILTIN, reason="Requires breakpoint() builtin"

View File

@ -295,7 +295,7 @@ def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=True,
universal_newlines=True,
text=True,
).stdout
except (OSError, subprocess.CalledProcessError):
pytest.skip("bash is not available")