From 575ae48105a34c9762f22fe66dd47b8d2c9606d4 Mon Sep 17 00:00:00 2001 From: gpotter2 Date: Thu, 29 Oct 2020 17:34:45 +0100 Subject: [PATCH] Upgrade to mypy 0.790 --- .github/workflows/unittests.yml | 2 +- scapy/compat.py | 2 +- scapy/layers/can.py | 18 +++++++++--------- scapy/main.py | 6 +++--- tox.ini | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index fb8b072cc..5336c627f 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -44,7 +44,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.8 - name: Install tox run: pip install tox - name: Run mypy diff --git a/scapy/compat.py b/scapy/compat.py index 14428b084..a8b6d60ae 100644 --- a/scapy/compat.py +++ b/scapy/compat.py @@ -156,7 +156,7 @@ else: Set = _FakeType("Set", set) # type: ignore Tuple = _FakeType("Tuple") Type = _FakeType("Type", type) - TypeVar = _FakeType("TypeVar") + TypeVar = _FakeType("TypeVar") # type: ignore Union = _FakeType("Union") class Sized(object): # type: ignore diff --git a/scapy/layers/can.py b/scapy/layers/can.py index 35caa696b..093c590a0 100644 --- a/scapy/layers/can.py +++ b/scapy/layers/can.py @@ -28,6 +28,7 @@ from scapy.layers.l2 import CookedLinux from scapy.error import Scapy_Exception from scapy.plist import PacketList from scapy.supersocket import SuperSocket +from scapy.utils import _ByteStream __all__ = ["CAN", "SignalPacket", "SignalField", "LESignedSignalField", "LEUnsignedSignalField", "LEFloatSignalField", "BEFloatSignalField", @@ -380,21 +381,20 @@ class CandumpReader: @staticmethod def open(filename): - # type: (Union[IO[Any], str]) -> Tuple[str, IO[Any]] + # type: (Union[IO[bytes], str]) -> Tuple[str, _ByteStream] """Open (if necessary) filename.""" - if isinstance(filename, six.string_types): - filename = cast(str, filename) + if isinstance(filename, str): try: - fdesc = gzip.open(filename, "rb") + fdesc = gzip.open(filename, "rb") # type: _ByteStream # try read to cause exception fdesc.read(1) fdesc.seek(0) except IOError: fdesc = open(filename, "rb") + return filename, fdesc else: - fdesc = cast(IO[Any], filename) - filename = getattr(fdesc, "name", "No name") - return cast(str, filename), fdesc + name = getattr(filename, "name", "No name") + return name, filename def next(self): # type: () -> Packet @@ -424,10 +424,10 @@ class CandumpReader: is_log_file_format = orb(line[0]) == orb(b"(") if is_log_file_format: - t, intf, f = line.split() + t_b, intf, f = line.split() idn, data = f.split(b'#') le = None - t = float(t[1:-1]) + t = float(t_b[1:-1]) # type: Optional[float] else: h, data = line.split(b']') intf, idn, le = h.split() diff --git a/scapy/main.py b/scapy/main.py index 8b6ece823..1ac67f305 100644 --- a/scapy/main.py +++ b/scapy/main.py @@ -225,7 +225,7 @@ def list_contrib(name=None, # type: Optional[str] ret=False, # type: bool _debug=False # type: bool ): - # type: (...) -> Optional[List[Dict[str, Union[str, None]]]] + # type: (...) -> Optional[List[Dict[str, str]]] """Show the list of all existing contribs. :param name: filter to search the contribs @@ -244,7 +244,7 @@ def list_contrib(name=None, # type: Optional[str] name = "*.py" elif "*" not in name and "?" not in name and not name.endswith(".py"): name += ".py" - results = [] # type: List[Dict[str, Union[str, None]]] + results = [] # type: List[Dict[str, str]] dir_path = os.path.join(os.path.dirname(__file__), "contrib") if sys.version_info >= (3, 5): name = os.path.join(dir_path, "**", name) @@ -258,7 +258,7 @@ def list_contrib(name=None, # type: Optional[str] continue if mod.endswith(".py"): mod = mod[:-3] - desc = {"description": None, "status": None, "name": mod} + desc = {"description": "", "status": "", "name": mod} with io.open(f, errors="replace") as fd: for line in fd: if line[0] != "#": diff --git a/tox.ini b/tox.ini index 0dd00ef44..6cddece7f 100644 --- a/tox.ini +++ b/tox.ini @@ -81,7 +81,7 @@ commands = [testenv:mypy] description = "Check Scapy compliance against static typing" skip_install = true -deps = mypy==0.782 +deps = mypy==0.790 typing commands = python .config/mypy/mypy_check.py