From 104883df410985ae7e977f3c2469fc0fe951f48f Mon Sep 17 00:00:00 2001 From: Pieter Marsman Date: Tue, 12 Oct 2021 20:22:58 +0200 Subject: [PATCH] Replace typing-extensions Literal with the type of the Literal & run mypy, nosetest and sphinx in there own environment on cicd (#677) * Improve tox.ini by running flake8, mypy, nosetests and sphinx in there own environment. Improves isolation. Dependencies of one package won't influence the next. This should fail for the current setup with typing-extensions. * Try to fix actually running tox tests on travis * Use recent tox * Fix using Literal[False] for open_filename. None has the same true value as False, and therefore it does not matter. * Replace typing_extensions.Literal by the type of the literal * Add line to CHANGELOG.md --- .travis.yml | 2 +- CHANGELOG.md | 1 + pdfminer/utils.py | 5 ++--- tools/pdf2txt.py | 3 +-- tox.ini | 32 +++++++++++++++++++++++++------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1ec881..34cf5b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ python: - "3.8" - "3.9" install: - - pip install tox==3.14.0 tox-travis flake8 + - pip install tox tox-travis script: - tox -r diff --git a/CHANGELOG.md b/CHANGELOG.md index 29059ac..8b13686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Support for Python 3.4 and 3.5 ([#522](https://github.com/pdfminer/pdfminer.six/pull/522)) - Unused dependency on `sortedcontainers` package ([#525](https://github.com/pdfminer/pdfminer.six/pull/525)) - Support for non-standard output streams that are not binary ([#523](https://github.com/pdfminer/pdfminer.six/pull/523)) +- Dependency on typing-extensions introduced by [#661](https://github.com/pdfminer/pdfminer.six/pull/661) ([#677](https://github.com/pdfminer/pdfminer.six/pull/677)) ## [20201018] diff --git a/pdfminer/utils.py b/pdfminer/utils.py index a5cf033..d483a48 100644 --- a/pdfminer/utils.py +++ b/pdfminer/utils.py @@ -7,7 +7,6 @@ import struct from typing import (Any, BinaryIO, Callable, Dict, Generic, Iterable, Iterator, List, Optional, Set, TextIO, Tuple, TypeVar, Union, TYPE_CHECKING, cast) -from typing_extensions import Literal from html import escape if TYPE_CHECKING: @@ -55,10 +54,10 @@ class open_filename(object): exc_type: object, exc_val: object, exc_tb: object - ) -> Literal[False]: + ) -> None: if self.closing: self.file_handler.close() - return False + return def make_compat_bytes(in_str: str) -> bytes: diff --git a/tools/pdf2txt.py b/tools/pdf2txt.py index 47e2c79..8f7896c 100755 --- a/tools/pdf2txt.py +++ b/tools/pdf2txt.py @@ -5,7 +5,6 @@ import argparse import logging import sys from typing import Any, Container, Iterable, List, Optional, Union -from typing_extensions import Literal import pdfminer.high_level from pdfminer.layout import LAParams @@ -18,7 +17,7 @@ OUTPUT_TYPES = ((".htm", "html"), (".xml", "xml"), (".tag", "tag")) -FloatOrDisabled = Union[float, Literal["disabled"]] +FloatOrDisabled = Union[float, str] # Union[float, Literal["disabled"]] def float_or_disabled(x: str) -> FloatOrDisabled: diff --git a/tox.ini b/tox.ini index 2a25d50..af5d36f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,33 @@ [tox] -envlist = py{36,37,38,3.9} +envlist = py{36,37,38,39}-{nose,flake8,mypy,docs} -[testenv] -extras = - dev - docs -whitelist_externals = +[testenv:py{36,37,38,39}-nose] +deps = + nose +allowlist_externals = + nosetests +commands = + nosetests --nologcapture + +[testenv:py{36,37,38,39}-flake8] +deps = + flake8 +allowlist_externals = flake8 commands = flake8 pdfminer/ tools/ tests/ --count --statistics + +[testenv:py{36,37,38,39}-mypy] +deps = + mypy +allowlist_externals = + mypy +commands = mypy --install-types --non-interactive --show-error-codes . - nosetests --nologcapture + +[testenv:py{36,37,38,39}-docs] +extras = + docs +commands = python -m sphinx -b html docs/source docs/build/html python -m sphinx -b doctest docs/source docs/build/doctest