From 3c1ea6dd44b10f9feedb83a7493887963857922a Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 7 Jul 2023 04:34:08 +0800 Subject: [PATCH 01/17] add typing and py.typed --- setup.py | 1 + wcwidth/__init__.pyi | 16 ++++++++++++++++ wcwidth/py.typed | 0 3 files changed, 17 insertions(+) create mode 100644 wcwidth/__init__.pyi create mode 100644 wcwidth/py.typed diff --git a/setup.py b/setup.py index fce95f4..c1094a4 100755 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ def main(): url='https://github.com/jquast/wcwidth', package_data={ '': ['LICENSE', '*.rst'], + 'wcwidth': ['py.typed', '*.pyi'], }, zip_safe=True, classifiers=[ diff --git a/wcwidth/__init__.pyi b/wcwidth/__init__.pyi new file mode 100644 index 0000000..7b7a83c --- /dev/null +++ b/wcwidth/__init__.pyi @@ -0,0 +1,16 @@ +from typing import Optional, Tuple + + +def wcwidth(wc: str, unicode_version: str = ...) -> int: + ... + + +def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): + ... + + +def list_versions() -> Tuple[str]: + ... + + +__version__: str = ... diff --git a/wcwidth/py.typed b/wcwidth/py.typed new file mode 100644 index 0000000..e69de29 From 07148241c2a3e3b1332e383ee3564e43fd9b1ba9 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Wed, 13 Sep 2023 01:58:17 +0800 Subject: [PATCH 02/17] fix mypy --- wcwidth/__init__.py | 16 ++++++---------- wcwidth/__init__.pyi | 16 ---------------- wcwidth/unicode_versions.pyi | 2 ++ wcwidth/wcwidth.pyi | 24 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 26 deletions(-) delete mode 100644 wcwidth/__init__.pyi create mode 100644 wcwidth/unicode_versions.pyi create mode 100644 wcwidth/wcwidth.pyi diff --git a/wcwidth/__init__.py b/wcwidth/__init__.py index ec554c3..5e7d38a 100644 --- a/wcwidth/__init__.py +++ b/wcwidth/__init__.py @@ -9,20 +9,16 @@ # any future version. # local -from .wcwidth import ZERO_WIDTH # noqa -from .wcwidth import (WIDE_EASTASIAN, - wcwidth, - wcswidth, - _bisearch, - list_versions, - _wcmatch_version, - _wcversion_value) +from .wcwidth import wcwidth, wcswidth, _bisearch, _wcmatch_version, _wcversion_value +from .table_wide import WIDE_EASTASIAN # noqa +from .table_zero import ZERO_WIDTH # noqa +from .unicode_versions import list_versions # The __all__ attribute defines the items exported from statement, # 'from wcwidth import *', but also to say, "This is the public API". -__all__ = ('wcwidth', 'wcswidth', 'list_versions') +__all__ = ("wcwidth", "wcswidth", "list_versions") # We also used pkg_resources to load unicode version tables from version.json, # generated by bin/update-tables.py, but some environments are unable to # import pkg_resources for one reason or another, yikes! -__version__ = '0.2.6' +__version__ = "0.2.6" diff --git a/wcwidth/__init__.pyi b/wcwidth/__init__.pyi deleted file mode 100644 index 7b7a83c..0000000 --- a/wcwidth/__init__.pyi +++ /dev/null @@ -1,16 +0,0 @@ -from typing import Optional, Tuple - - -def wcwidth(wc: str, unicode_version: str = ...) -> int: - ... - - -def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): - ... - - -def list_versions() -> Tuple[str]: - ... - - -__version__: str = ... diff --git a/wcwidth/unicode_versions.pyi b/wcwidth/unicode_versions.pyi new file mode 100644 index 0000000..86e5a7c --- /dev/null +++ b/wcwidth/unicode_versions.pyi @@ -0,0 +1,2 @@ +def list_versions() -> list[str]: + ... diff --git a/wcwidth/wcwidth.pyi b/wcwidth/wcwidth.pyi new file mode 100644 index 0000000..777a446 --- /dev/null +++ b/wcwidth/wcwidth.pyi @@ -0,0 +1,24 @@ +from typing import Optional + + +def wcwidth(wc: str, unicode_version: str = ...) -> int: + ... + + +def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): + ... + + +def _bisearch(ucs: int, table: list[tuple[int, int]]) -> int: + ... + + +def _wcversion_value(ver_string: str) -> tuple[int, ...]: + ... + + +def _wcmatch_version(given_version: str) -> str: + ... + + +__version__: str = ... From 487b31a9f9ab5e0162484e0f0b7899b3ca94e864 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Wed, 13 Sep 2023 01:59:08 +0800 Subject: [PATCH 03/17] revert unexpected change --- wcwidth/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wcwidth/__init__.py b/wcwidth/__init__.py index 5e7d38a..49cd7e4 100644 --- a/wcwidth/__init__.py +++ b/wcwidth/__init__.py @@ -16,9 +16,9 @@ # The __all__ attribute defines the items exported from statement, # 'from wcwidth import *', but also to say, "This is the public API". -__all__ = ("wcwidth", "wcswidth", "list_versions") +__all__ = ('wcwidth', 'wcswidth', 'list_versions') # We also used pkg_resources to load unicode version tables from version.json, # generated by bin/update-tables.py, but some environments are unable to # import pkg_resources for one reason or another, yikes! -__version__ = "0.2.6" +__version__ = '0.2.6' From 793edbe2bd6fc8ddcf96cde4abf05e525a44cc45 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 17 Nov 2023 17:00:36 +0800 Subject: [PATCH 04/17] Update wcwidth.pyi --- wcwidth/wcwidth.pyi | 3 --- 1 file changed, 3 deletions(-) diff --git a/wcwidth/wcwidth.pyi b/wcwidth/wcwidth.pyi index 777a446..4642608 100644 --- a/wcwidth/wcwidth.pyi +++ b/wcwidth/wcwidth.pyi @@ -19,6 +19,3 @@ def _wcversion_value(ver_string: str) -> tuple[int, ...]: def _wcmatch_version(given_version: str) -> str: ... - - -__version__: str = ... From 3701f7f073026d1abd7ffae7b1a90c2932bbec91 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 20 Nov 2023 16:11:25 +0800 Subject: [PATCH 05/17] add stubtest --- .github/workflows/ci.yml | 12 ++++++++++++ wcwidth/__init__.py | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6653982..8df01eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,3 +152,15 @@ jobs: if: ${{ failure() }} env: CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} + + typing: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + - run: pip install mypy + - name: Run tests + run: stubtest wcwidth diff --git a/wcwidth/__init__.py b/wcwidth/__init__.py index 91e18db..6160396 100644 --- a/wcwidth/__init__.py +++ b/wcwidth/__init__.py @@ -9,13 +9,13 @@ # any future version. # local -from .wcwidth import ZERO_WIDTH # noqa -from .wcwidth import (WIDE_EASTASIAN, - VS16_NARROW_TO_WIDE, - wcwidth, +from .unicode_versions import list_versions +from .table_zero import ZERO_WIDTH +from .table_wide import WIDE_EASTASIAN +from .table_vs16 import VS16_NARROW_TO_WIDE +from .wcwidth import (wcwidth, wcswidth, _bisearch, - list_versions, _wcmatch_version, _wcversion_value) From 7ddf896b1fb7c70ba8108aa31c2c2ec56b7f4636 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 20 Nov 2023 16:13:12 +0800 Subject: [PATCH 06/17] fix typing testing --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8df01eb..ab6383a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,5 +162,6 @@ jobs: with: python-version: '3.x' - run: pip install mypy + - run: pip install -e . - name: Run tests run: stubtest wcwidth From d9cf7f6f102dd2ca406b834d50085746014dc9c0 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 20 Nov 2023 16:15:35 +0800 Subject: [PATCH 07/17] add tox job --- tox.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tox.ini b/tox.ini index 5ffb5ff..f59b792 100644 --- a/tox.ini +++ b/tox.ini @@ -193,3 +193,8 @@ basepython = python{env:TOXPYTHON:{env:TRAVIS_PYTHON_VERSION:3.10}} passenv = TOXENV,CI,TRAVIS,TRAVIS_*,CODECOV_* deps = codecov commands = codecov -e TOXENV + +[testenv:typing] +basepython = python3.12 +deps = mypy +commands = stubtest wcwidth From d26a6eec53e9cefed94100d514dfb88e09ae9fb3 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 20 Nov 2023 17:05:17 +0800 Subject: [PATCH 08/17] import --- wcwidth/__init__.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/wcwidth/__init__.py b/wcwidth/__init__.py index 6160396..d1b8373 100644 --- a/wcwidth/__init__.py +++ b/wcwidth/__init__.py @@ -10,14 +10,10 @@ # local from .unicode_versions import list_versions -from .table_zero import ZERO_WIDTH -from .table_wide import WIDE_EASTASIAN -from .table_vs16 import VS16_NARROW_TO_WIDE -from .wcwidth import (wcwidth, - wcswidth, - _bisearch, - _wcmatch_version, - _wcversion_value) +from .table_zero import ZERO_WIDTH # noqa +from .table_wide import WIDE_EASTASIAN # noqa +from .table_vs16 import VS16_NARROW_TO_WIDE # noqa +from .wcwidth import wcwidth, wcswidth, _bisearch, _wcmatch_version, _wcversion_value # The __all__ attribute defines the items exported from statement, # 'from wcwidth import *', but also to say, "This is the public API". From 3de00b46903f1e3fd25d7bba7de82d907ca87899 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Tue, 21 Nov 2023 19:21:15 +0800 Subject: [PATCH 09/17] add mypy in requirements && update requirements --- docs/requirements.txt | 4 ++-- requirements-tests37.in | 2 ++ requirements-tests37.txt | 12 +++++++++++- requirements-tests39.in | 1 + requirements-tests39.txt | 14 ++++++++++---- requirements-update.txt | 2 +- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 2d6d4b1..edad8f6 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,11 +6,11 @@ # alabaster==0.7.13 # via sphinx -babel==2.12.1 +babel==2.13.1 # via sphinx certifi==2023.7.22 # via requests -charset-normalizer==3.3.0 +charset-normalizer==3.3.2 # via requests docutils==0.17.1 # via diff --git a/requirements-tests37.in b/requirements-tests37.in index d1b25ef..74e1b11 100644 --- a/requirements-tests37.in +++ b/requirements-tests37.in @@ -4,3 +4,5 @@ pytest-cov coverage[toml]<6 importlib_metadata; python_version < '3.8' pytest-benchmark +mypy +typing; python_version < '3.5' diff --git a/requirements-tests37.txt b/requirements-tests37.txt index b16ca3e..15e689c 100644 --- a/requirements-tests37.txt +++ b/requirements-tests37.txt @@ -18,6 +18,10 @@ importlib-metadata==6.7.0 ; python_version < "3.8" # pytest iniconfig==2.0.0 # via pytest +mypy==1.4.1 + # via -r requirements-tests37.in +mypy-extensions==1.0.0 + # via mypy packaging==23.2 # via pytest pluggy==1.2.0 @@ -39,7 +43,13 @@ toml==0.10.2 # via # coverage # pytest +tomli==2.0.1 + # via mypy +typed-ast==1.5.5 + # via mypy typing-extensions==4.7.1 - # via importlib-metadata + # via + # importlib-metadata + # mypy zipp==3.15.0 # via importlib-metadata diff --git a/requirements-tests39.in b/requirements-tests39.in index af7c1c5..0e10fb4 100644 --- a/requirements-tests39.in +++ b/requirements-tests39.in @@ -13,3 +13,4 @@ pylint>=2.15 astroid>=2.11 wrapt>=1.14 pytest-benchmark +mypy diff --git a/requirements-tests39.txt b/requirements-tests39.txt index 179dec1..53351ec 100644 --- a/requirements-tests39.txt +++ b/requirements-tests39.txt @@ -10,7 +10,7 @@ astroid==3.0.1 # pylint autopep8==2.0.4 # via -r requirements-tests39.in -charset-normalizer==3.3.0 +charset-normalizer==3.3.2 # via docformatter coverage==7.3.2 # via pytest-cov @@ -38,6 +38,10 @@ mccabe==0.7.0 # via # flake8 # pylint +mypy==1.6.1 + # via -r requirements-tests39.in +mypy-extensions==1.0.0 + # via mypy packaging==23.2 # via pytest pbr==5.11.1 @@ -60,9 +64,9 @@ pygments==2.16.1 # via # -r requirements-tests39.in # doc8 -pylint==3.0.1 +pylint==3.0.2 # via -r requirements-tests39.in -pytest==7.4.2 +pytest==7.4.3 # via # -r requirements-tests39.in # pytest-benchmark @@ -84,13 +88,15 @@ tomli==2.0.1 # autopep8 # coverage # doc8 + # mypy # pylint # pytest -tomlkit==0.12.1 +tomlkit==0.12.2 # via pylint typing-extensions==4.8.0 # via # astroid + # mypy # pylint untokenize==0.1.1 # via docformatter diff --git a/requirements-update.txt b/requirements-update.txt index 49165f6..5673eac 100644 --- a/requirements-update.txt +++ b/requirements-update.txt @@ -6,7 +6,7 @@ # certifi==2023.7.22 # via requests -charset-normalizer==3.3.0 +charset-normalizer==3.3.2 # via requests idna==3.4 # via requests From bb6f5ebd21140177893f9b76b2e4c3e5ba5fe8de Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Tue, 21 Nov 2023 19:21:52 +0800 Subject: [PATCH 10/17] add typing tests --- tests/typing/__init__.py | 0 tests/typing/test_success.py | 63 ++++++++++++++++++++++++++++++++++++ tox.ini | 1 + 3 files changed, 64 insertions(+) create mode 100644 tests/typing/__init__.py create mode 100644 tests/typing/test_success.py diff --git a/tests/typing/__init__.py b/tests/typing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/typing/test_success.py b/tests/typing/test_success.py new file mode 100644 index 0000000..20355a9 --- /dev/null +++ b/tests/typing/test_success.py @@ -0,0 +1,63 @@ +import sys +import wcwidth +from typing import Tuple + + +if sys.version_info >= (3,): + unicode = str + + +def test_list_versions(): # type: () -> None + versions = wcwidth.list_versions() # type: Tuple[str, ...] + assert isinstance(versions, tuple) + for version in versions: + assert isinstance(version, str) + + +def test_wcwidth(): # type: () -> None + width = wcwidth.wcwidth("a") # type: int + assert isinstance(width, int) + width = wcwidth.wcwidth(u"啊") + assert isinstance(width, int) + + width = wcwidth.wcwidth("b", "9.0") + assert isinstance(width, int) + width = wcwidth.wcwidth("b", u"9.0") + assert isinstance(width, int) + + +def test_wcswidth(): # type: () -> None + width = wcwidth.wcswidth("hello, world") # type: int + assert isinstance(width, int) + width = wcwidth.wcswidth(u"你好,世界") + assert isinstance(width, int) + + width = wcwidth.wcswidth(u"你好,世界", 5) + assert isinstance(width, int) + + width = wcwidth.wcswidth("hello, world", unicode_version="9.0") + assert isinstance(width, int) + width = wcwidth.wcswidth("hello, world", unicode_version=u"9.0") + assert isinstance(width, int) + + width = wcwidth.wcswidth(u"你好,世界", 5, "9.0") + assert isinstance(width, int) + + +def test__bisearch(): # type: () -> None + found = wcwidth._bisearch(6, [(1, 2), (4, 7)]) # type: int + assert isinstance(found, int) + + +def test__wcversion_value(): # type: () -> None + version = wcwidth._wcversion_value("12.1.0") # type: Tuple[int, ...] + assert isinstance(version, tuple) + for number in version: + assert isinstance(number, int) + + +def test__wcmatch_version(): # type: () -> None + version_str = wcwidth._wcmatch_version("auto") # type: str + assert isinstance(version_str, str) + version_unicode = wcwidth._wcmatch_version(u"auto") # type: unicode + assert isinstance(version_unicode, unicode) diff --git a/tox.ini b/tox.ini index f59b792..1d74fea 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,7 @@ commands = {envpython} -m pytest --cov-config={toxinidir}/tox.ini {posargs:\ } \ --log-format='%(levelname)s %(relativeCreated)2.2f %(filename)s:%(lineno)d %(message)s' \ tests + {envpython} -m mypy tests/typing passenv = TEST_QUICK,TEST_KEYBOARD,TEST_RAW From 317a4a2ce9b6ee9129c287c9eec106d30ff73fb1 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Tue, 21 Nov 2023 19:25:48 +0800 Subject: [PATCH 11/17] convert CRLF to LF for *.pyi --- wcwidth/unicode_versions.pyi | 4 ++-- wcwidth/wcwidth.pyi | 42 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/wcwidth/unicode_versions.pyi b/wcwidth/unicode_versions.pyi index 86e5a7c..f64712e 100644 --- a/wcwidth/unicode_versions.pyi +++ b/wcwidth/unicode_versions.pyi @@ -1,2 +1,2 @@ -def list_versions() -> list[str]: - ... +def list_versions() -> list[str]: + ... diff --git a/wcwidth/wcwidth.pyi b/wcwidth/wcwidth.pyi index 4642608..5f993f4 100644 --- a/wcwidth/wcwidth.pyi +++ b/wcwidth/wcwidth.pyi @@ -1,21 +1,21 @@ -from typing import Optional - - -def wcwidth(wc: str, unicode_version: str = ...) -> int: - ... - - -def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): - ... - - -def _bisearch(ucs: int, table: list[tuple[int, int]]) -> int: - ... - - -def _wcversion_value(ver_string: str) -> tuple[int, ...]: - ... - - -def _wcmatch_version(given_version: str) -> str: - ... +from typing import Optional + + +def wcwidth(wc: str, unicode_version: str = ...) -> int: + ... + + +def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): + ... + + +def _bisearch(ucs: int, table: list[tuple[int, int]]) -> int: + ... + + +def _wcversion_value(ver_string: str) -> tuple[int, ...]: + ... + + +def _wcmatch_version(given_version: str) -> str: + ... From 675311660ccbc7201d8a396adb6b7b6fc88ee9a1 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Tue, 21 Nov 2023 19:30:17 +0800 Subject: [PATCH 12/17] fix type for list_versions() --- wcwidth/unicode_versions.py | 2 +- wcwidth/unicode_versions.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wcwidth/unicode_versions.py b/wcwidth/unicode_versions.py index 4e9ccbf..3b52360 100644 --- a/wcwidth/unicode_versions.py +++ b/wcwidth/unicode_versions.py @@ -13,7 +13,7 @@ def list_versions(): ``unicode_version`` to the ``wcwidth()`` family of functions. :returns: Supported Unicode version numbers in ascending sorted order. - :rtype: list[str] + :rtype: tuple[str, ...] """ return ( "4.1.0", diff --git a/wcwidth/unicode_versions.pyi b/wcwidth/unicode_versions.pyi index f64712e..caff231 100644 --- a/wcwidth/unicode_versions.pyi +++ b/wcwidth/unicode_versions.pyi @@ -1,2 +1,2 @@ -def list_versions() -> list[str]: +def list_versions() -> tuple[str, ...]: ... From febff4595cabcef6e47ae268c3e04d7b28592333 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 Nov 2023 20:41:56 +0800 Subject: [PATCH 13/17] using tox --- .github/workflows/ci.yml | 6 ++---- requirements-tests37.in | 2 -- requirements-tests37.txt | 28 ++++++---------------------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a09a1b..bc5e608 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,7 +176,5 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.x' - - run: pip install mypy - - run: pip install -e . - - name: Run tests - run: stubtest wcwidth \ No newline at end of file + - run: pip install tox + - run: tox -e typing diff --git a/requirements-tests37.in b/requirements-tests37.in index 74e1b11..d1b25ef 100644 --- a/requirements-tests37.in +++ b/requirements-tests37.in @@ -4,5 +4,3 @@ pytest-cov coverage[toml]<6 importlib_metadata; python_version < '3.8' pytest-benchmark -mypy -typing; python_version < '3.5' diff --git a/requirements-tests37.txt b/requirements-tests37.txt index 15e689c..7a67cb8 100644 --- a/requirements-tests37.txt +++ b/requirements-tests37.txt @@ -1,27 +1,21 @@ # -# This file is autogenerated by pip-compile with Python 3.7 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --allow-unsafe --no-emit-index-url --output-file=requirements-tests37.txt --resolver=backtracking --strip-extras requirements-tests37.in +# pip-compile --allow-unsafe --no-emit-index-url --output-file=requirements-tests37.txt --strip-extras requirements-tests37.in # +atomicwrites==1.4.1 + # via pytest attrs==23.1.0 # via pytest +colorama==0.4.6 + # via pytest coverage==5.5 # via # -r requirements-tests37.in # pytest-cov -importlib-metadata==6.7.0 ; python_version < "3.8" - # via - # -r requirements-tests37.in - # attrs - # pluggy - # pytest iniconfig==2.0.0 # via pytest -mypy==1.4.1 - # via -r requirements-tests37.in -mypy-extensions==1.0.0 - # via mypy packaging==23.2 # via pytest pluggy==1.2.0 @@ -43,13 +37,3 @@ toml==0.10.2 # via # coverage # pytest -tomli==2.0.1 - # via mypy -typed-ast==1.5.5 - # via mypy -typing-extensions==4.7.1 - # via - # importlib-metadata - # mypy -zipp==3.15.0 - # via importlib-metadata From 85b39b0b10c543035bae9804e9e876c89371fa03 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 Nov 2023 20:44:00 +0800 Subject: [PATCH 14/17] fix typing --- wcwidth/wcwidth.pyi | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/wcwidth/wcwidth.pyi b/wcwidth/wcwidth.pyi index 5f993f4..d197b2d 100644 --- a/wcwidth/wcwidth.pyi +++ b/wcwidth/wcwidth.pyi @@ -1,12 +1,23 @@ -from typing import Optional +from typing import Optional, AnyStr +import sys -def wcwidth(wc: str, unicode_version: str = ...) -> int: - ... +if sys.version_info >= (3,): + def wcwidth(wc: str, unicode_version: str = ...) -> int: + ... + + + def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): + ... +else: + def wcwidth(wc: AnyStr, unicode_version: str = ...) -> int: + ... + + + def wcswidth(pwcs: AnyStr, n: Optional[int] = None, unicode_version: str = ...): + ... -def wcswidth(pwcs: str, n: Optional[int] = None, unicode_version: str = ...): - ... def _bisearch(ucs: int, table: list[tuple[int, int]]) -> int: From 68363d7413616b742a69e8f8c310d5110da1e18e Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 Nov 2023 20:45:05 +0800 Subject: [PATCH 15/17] revert some file --- requirements-tests37.in | 1 - requirements-tests37.txt | 25 +++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/requirements-tests37.in b/requirements-tests37.in index d1b25ef..d782c37 100644 --- a/requirements-tests37.in +++ b/requirements-tests37.in @@ -3,4 +3,3 @@ pytest<7 pytest-cov coverage[toml]<6 importlib_metadata; python_version < '3.8' -pytest-benchmark diff --git a/requirements-tests37.txt b/requirements-tests37.txt index 7a67cb8..4780dcf 100644 --- a/requirements-tests37.txt +++ b/requirements-tests37.txt @@ -1,39 +1,40 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.7 # by the following command: # -# pip-compile --allow-unsafe --no-emit-index-url --output-file=requirements-tests37.txt --strip-extras requirements-tests37.in +# pip-compile --allow-unsafe --no-emit-index-url --output-file=requirements-tests37.txt --resolver=backtracking --strip-extras requirements-tests37.in # -atomicwrites==1.4.1 - # via pytest attrs==23.1.0 # via pytest -colorama==0.4.6 - # via pytest coverage==5.5 # via # -r requirements-tests37.in # pytest-cov +importlib-metadata==6.7.0 ; python_version < "3.8" + # via + # -r requirements-tests37.in + # attrs + # pluggy + # pytest iniconfig==2.0.0 # via pytest -packaging==23.2 +packaging==23.1 # via pytest pluggy==1.2.0 # via pytest py==1.11.0 # via pytest -py-cpuinfo==9.0.0 - # via pytest-benchmark pytest==6.2.5 # via # -r requirements-tests37.in - # pytest-benchmark # pytest-cov -pytest-benchmark==4.0.0 - # via -r requirements-tests37.in pytest-cov==4.1.0 # via -r requirements-tests37.in toml==0.10.2 # via # coverage # pytest +typing-extensions==4.7.1 + # via importlib-metadata +zipp==3.15.0 + # via importlib-metadata From 9b2f794d2a55824054a2262301ddc013944ccbed Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 Nov 2023 20:48:54 +0800 Subject: [PATCH 16/17] fix --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 1d74fea..d19bb06 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,6 @@ commands = {envpython} -m pytest --cov-config={toxinidir}/tox.ini {posargs:\ } \ --log-format='%(levelname)s %(relativeCreated)2.2f %(filename)s:%(lineno)d %(message)s' \ tests - {envpython} -m mypy tests/typing passenv = TEST_QUICK,TEST_KEYBOARD,TEST_RAW @@ -198,4 +197,7 @@ commands = codecov -e TOXENV [testenv:typing] basepython = python3.12 deps = mypy -commands = stubtest wcwidth +commands = + stubtest wcwidth + {envpython} -m mypy tests/typing + From 31908371fb7e554be13952ad6ff9fa83050e92a4 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 Nov 2023 20:54:39 +0800 Subject: [PATCH 17/17] remove testing --- tests/typing/__init__.py | 0 tests/typing/test_success.py | 63 ------------------------------------ tox.ini | 1 - 3 files changed, 64 deletions(-) delete mode 100644 tests/typing/__init__.py delete mode 100644 tests/typing/test_success.py diff --git a/tests/typing/__init__.py b/tests/typing/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/typing/test_success.py b/tests/typing/test_success.py deleted file mode 100644 index 20355a9..0000000 --- a/tests/typing/test_success.py +++ /dev/null @@ -1,63 +0,0 @@ -import sys -import wcwidth -from typing import Tuple - - -if sys.version_info >= (3,): - unicode = str - - -def test_list_versions(): # type: () -> None - versions = wcwidth.list_versions() # type: Tuple[str, ...] - assert isinstance(versions, tuple) - for version in versions: - assert isinstance(version, str) - - -def test_wcwidth(): # type: () -> None - width = wcwidth.wcwidth("a") # type: int - assert isinstance(width, int) - width = wcwidth.wcwidth(u"啊") - assert isinstance(width, int) - - width = wcwidth.wcwidth("b", "9.0") - assert isinstance(width, int) - width = wcwidth.wcwidth("b", u"9.0") - assert isinstance(width, int) - - -def test_wcswidth(): # type: () -> None - width = wcwidth.wcswidth("hello, world") # type: int - assert isinstance(width, int) - width = wcwidth.wcswidth(u"你好,世界") - assert isinstance(width, int) - - width = wcwidth.wcswidth(u"你好,世界", 5) - assert isinstance(width, int) - - width = wcwidth.wcswidth("hello, world", unicode_version="9.0") - assert isinstance(width, int) - width = wcwidth.wcswidth("hello, world", unicode_version=u"9.0") - assert isinstance(width, int) - - width = wcwidth.wcswidth(u"你好,世界", 5, "9.0") - assert isinstance(width, int) - - -def test__bisearch(): # type: () -> None - found = wcwidth._bisearch(6, [(1, 2), (4, 7)]) # type: int - assert isinstance(found, int) - - -def test__wcversion_value(): # type: () -> None - version = wcwidth._wcversion_value("12.1.0") # type: Tuple[int, ...] - assert isinstance(version, tuple) - for number in version: - assert isinstance(number, int) - - -def test__wcmatch_version(): # type: () -> None - version_str = wcwidth._wcmatch_version("auto") # type: str - assert isinstance(version_str, str) - version_unicode = wcwidth._wcmatch_version(u"auto") # type: unicode - assert isinstance(version_unicode, unicode) diff --git a/tox.ini b/tox.ini index d19bb06..93154b6 100644 --- a/tox.ini +++ b/tox.ini @@ -199,5 +199,4 @@ basepython = python3.12 deps = mypy commands = stubtest wcwidth - {envpython} -m mypy tests/typing