TypeError: Subscripted generics cannot be used with class and instance checks under python 3.9.0b1

See original GitHub issue

Problem Description

Running mitmproxy 5.1.1 under python 3.9.0b1 fails with TypeError: Subscripted generics cannot be used with class and instance checks. The test suite fails as well with hundreds of ERROR and FAILED tests.

Steps to reproduce the behavior:

  1. install mitmproxy 5.1.1 on Fedora rawhide
  2. mitmproxy
  3. pytest -v

There are:

=================== 303 failed, 994 passed, 2 xfailed, 115 warnings, 182 errors in 72.86s (0:01:12) ====================

Most of them throw a TypeError: Subscripted generics cannot be used with class and instance checks and have a stack trace similar to:

___________________________________ ERROR at setup of TestHTTPS.test_clientcert_dir ____________________________________

cls = <class 'test.mitmproxy.proxy.test_server.TestHTTPS'>

    @classmethod
    def setup_class(cls):
        cls.server = pathod.test.Daemon(
            ssl=cls.ssl,
            ssloptions=cls.ssloptions)
        cls.server2 = pathod.test.Daemon(
            ssl=cls.ssl,
            ssloptions=cls.ssloptions)
    
>       cls.options = cls.get_options()

test/mitmproxy/tservers.py:146: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/mitmproxy/tservers.py:179: in get_options
    return options.Options(
mitmproxy/options.py:50: in __init__
    self.add_option(
mitmproxy/optmanager.py:109: in add_option
    self._options[name] = _Option(name, typespec, default, help, choices)
mitmproxy/optmanager.py:34: in __init__
    typecheck.check_option_type(name, default, typespec)
mitmproxy/utils/typecheck.py:73: in check_option_type
    elif not isinstance(value, typeinfo):
/usr/lib64/python3.9/typing.py:649: in __instancecheck__
    return self.__subclasscheck__(type(obj))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Optional[str], cls = <class 'NoneType'>

    def __subclasscheck__(self, cls):
>       raise TypeError("Subscripted generics cannot be used with"
                        " class and instance checks")
E       TypeError: Subscripted generics cannot be used with class and instance checks

/usr/lib64/python3.9/typing.py:652: TypeError

System Information

Traceback (most recent call last):
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/bin/./mitmproxy", line 11, in <module>
    load_entry_point('mitmproxy==5.1.1', 'console_scripts', 'mitmproxy')()
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/tools/_main.py", line 147, in mitmproxy
    run(console.master.ConsoleMaster, cmdline.mitmproxy, args)
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/tools/_main.py", line 71, in run
    opts = options.Options()
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/options.py", line 50, in __init__
    self.add_option(
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/optmanager.py", line 109, in add_option
    self._options[name] = _Option(name, typespec, default, help, choices)
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/optmanager.py", line 34, in __init__
    typecheck.check_option_type(name, default, typespec)
  File "/builddir/build/BUILDROOT/mitmproxy-5.1.1-1.fc33.x86_64/usr/lib/python3.9/site-packages/mitmproxy/utils/typecheck.py", line 73, in check_option_type
    elif not isinstance(value, typeinfo):
  File "/usr/lib64/python3.9/typing.py", line 649, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "/usr/lib64/python3.9/typing.py", line 652, in __subclasscheck__
    raise TypeError("Subscripted generics cannot be used with"
TypeError: Subscripted generics cannot be used with class and instance checks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
AustinShalitcommented, Oct 31, 2020

Any updates on pushing a release?

3reactions
mikelei8291commented, Oct 21, 2020

Is this fixed in the released mitmproxy version? I still got this error when tried to run it with Python 3.9.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscripted generics cannot be used with class and instance ...
Ok found the problem. In 3.7, issubclass built-in method does not accept subscripted generics. This is a breaking change made in Python 3.7....
Read more >
extracting data from typing types - python - Stack Overflow
Checking the generic type of a typing object. To check if string_list_class is a list type, you can use the typing_inspect library: from ......
Read more >
Issue 44529: Using typing.Union in isinstance checks
msg396658 ‑ (view) Author: Kaleb Barrett (ktbarrett) Date: 2021‑06‑28 18:15 msg396671 ‑ (view) Author: Jack DeVries (jack__d) * Date: 2021‑06‑28 23:30 msg396694 ‑ (view) Author:...
Read more >
python - Subscriptable Type Hinting and Instance Checks
To do the instance check, use IsInstance , not isinstance . For example: Use IsInstance([1, 2, 3], List[int]). The code is also on...
Read more >
ActivePython 3.7.4 Documentation
Complete documentation for ActivePython 3.7.4.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found