Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Python 3.9+. #66

Closed
wants to merge 1 commit into from
Closed

Conversation

Apteryks
Copy link

Fixes #60.

Based on an idea in
#60 (comment).

@Apteryks
Copy link
Author

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.

@@ -75,7 +75,7 @@ def is_generic_type(tp):
"""
if NEW_TYPING:
return (isinstance(tp, type) and issubclass(tp, Generic) or
isinstance(tp, _GenericAlias) and
(isinstance(tp, _GenericAlias) or isinstance(tp, _SpecialGenericAlias)) and

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: isinstance accepts tuples of types and isinstance(tp, (_GenericAlias, _SpecialGenericAlias)) could be easier to read.

Copy link
Owner

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, there is also some error about TypedDict keys.

@Apteryks
Copy link
Author

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
Copy link
Author

Apteryks commented Jan 18, 2021

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
Copy link

fabaff commented Mar 7, 2021

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

@bnavigator
Copy link
Contributor

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

ilevkivskyi pushed a commit that referenced this pull request Mar 21, 2021
Another take at #66 which keeps compatibility with older Python versions.

Fixes #60
@ilevkivskyi
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is_generic_type(List) is False in 3.9
5 participants