ilevkivskyi / typing_inspect

Runtime inspection utilities for Python typing module
MIT License
350 stars 35 forks source link

Fix for Python 3.9+. #66

Closed Apteryks closed 3 years ago

Apteryks commented 3 years ago

Fixes https://github.com/ilevkivskyi/typing_inspect/issues/60.

Based on an idea in https://github.com/ilevkivskyi/typing_inspect/issues/60#issuecomment-683187584.

Apteryks commented 3 years ago

Not sure if that's the most correct fix (probably not, I haven't spent much time on it), but it at least allows the test suite to pass.

Apteryks commented 3 years ago

Thanks! Few comments:

* Please use a tuple of types in `isinstance()` as @jstasiak suggested.

* You should import `_SpecialGenericAlias` conditionally on Python version, otherwise tests will fail on other Python versions.

* There are dozen other places in the module where `_GenericAlias` is used, should they also be updated?

* It looks like this only change in itself is not sufficient to fix test failures on Python 3.9, as you can see from a [build I started](https://travis-ci.org/github/ilevkivskyi/typing_inspect/jobs/754857530), there is also some error about TypedDict keys.

Weird! Perhaps because I used the last 0.6.0 PyPI archive instead of the latest commit? Here it gave:

starting phase `check'
running "python setup.py" with command "test" and parameters ()
running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.
running egg_info
writing typing_inspect.egg-info/PKG-INFO
writing dependency_links to typing_inspect.egg-info/dependency_links.txt
writing requirements to typing_inspect.egg-info/requires.txt
writing top-level names to typing_inspect.egg-info/top_level.txt
reading manifest file 'typing_inspect.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'typing_inspect.egg-info/SOURCES.txt'
running build_ext
test_args (test_typing_inspect.GetUtilityTestCase) ... skipped 'Not supported in Python 3.7'
test_args_evaluated (test_typing_inspect.GetUtilityTestCase) ... ok
test_bound (test_typing_inspect.GetUtilityTestCase) ... ok
test_constraints (test_typing_inspect.GetUtilityTestCase) ... ok
test_generic_bases (test_typing_inspect.GetUtilityTestCase) ... ok
test_generic_type (test_typing_inspect.GetUtilityTestCase) ... ok
test_get_forward_arg (test_typing_inspect.GetUtilityTestCase) ... ok
test_last_args (test_typing_inspect.GetUtilityTestCase) ... skipped 'Not supported in Python 3.7'
test_last_origin (test_typing_inspect.GetUtilityTestCase) ... skipped 'Not supported in Python 3.7'
test_origin (test_typing_inspect.GetUtilityTestCase) ... ok
test_parameters (test_typing_inspect.GetUtilityTestCase) ... ok
test_typed_dict (test_typing_inspect.GetUtilityTestCase) ... ok
test_callable (test_typing_inspect.IsUtilityTestCase) ... ok
test_classvar (test_typing_inspect.IsUtilityTestCase) ... ok
test_generic (test_typing_inspect.IsUtilityTestCase) ... ok
test_is_forward_ref (test_typing_inspect.IsUtilityTestCase) ... ok
test_literal_type (test_typing_inspect.IsUtilityTestCase) ... ok
test_new_type (test_typing_inspect.IsUtilityTestCase) ... ok
test_optional_type (test_typing_inspect.IsUtilityTestCase) ... ok
test_tuple (test_typing_inspect.IsUtilityTestCase) ... ok
test_typevar (test_typing_inspect.IsUtilityTestCase) ... ok
test_union (test_typing_inspect.IsUtilityTestCase) ... ok

----------------------------------------------------------------------
Ran 22 tests in 0.003s

OK (skipped=3)

The package definition I used in Guix reads as:

(define-public python-typing-inspect
  (package
    (name "python-typing-inspect")
    (version "0.6.0")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "typing_inspect" version))
              (sha256
               (base32
                "1dzs9a1pr23dhbvmnvms2jv7l7jk26023g5ysf0zvnq8b791s6wg"))
              (patches (search-patches "python-typing-inspect-fix.patch"))))
    (build-system python-build-system)
    (propagated-inputs
     `(("python-mypy-extensions" ,python-mypy-extensions)
       ("python-typing-extensions" ,python-typing-extensions)))
    (home-page "https://github.com/ilevkivskyi/typing_inspect")
    (synopsis "API for inspection of types in the Python @code{typing} module")
    (description
     "The @code{typing_inspect} module defines experimental API for runtime
inspection of types defined in the Python standard typing module.")
    (license license:expat)))

As you can see if fetches its sources from the PyPI release 0.6.0 release.

Apteryks commented 3 years ago

Answering myself: yes, this patch fixes the issues when using the last release 0.6.0, but is not sufficient for what's in master (guix build --with-git-url=python-typing-inspect=https://github.com/ilevkivskyi/typing_inspect python-typing-inspect) gives the same errors as your CI job.

fabaff commented 3 years ago

This patch makes build for Python < 3.9 fail for me.

bnavigator commented 3 years ago

Fixed in #69 with the other Py3.9 fail of the test suite fixed in #68.

ilevkivskyi commented 3 years ago

@Apteryks Sorry, closing this in favor of the other PRs, thanks for your attempt!