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 interaction between typing_extensions and collections.abc #503

Merged
merged 11 commits into from
Dec 1, 2017

Conversation

ilevkivskyi
Copy link
Member

Fixes #501

The idea is straightforward: special classes in typing_extensions that have __extra__ should use a metaclass that fixes the problem in GenericMeta.__subclasscheck__ on older versions of typing.

Note that overriding __subclasscheck__ tries to mimic the behaviour in the new versions of typing. (I can't just use super().__subclasscheck__ on unaffected versions, since this changes call stack depth and therefore breaks a sys._getframe hack on some other versions of typing.)

@jabdoa2 Could you please check that this fixes the crash you found in dropbox/pyannotate#36

@jabdoa2
Copy link

jabdoa2 commented Nov 25, 2017

Installed typing from your repository:
sudo pip3 install git+https://github.com/ilevkivskyi/typehinting.git@fix-abc-extensions --upgrade

Unfortunately, the error still persists for me:

pyannotate mpf
Traceback (most recent call last):
  File "/usr/local/bin/pyannotate", line 11, in <module>
    load_entry_point('pyannotate', 'console_scripts', 'pyannotate')()
  File "/data/home/jan/cloud/flipper/src/pyannotate/pyannotate_tools/annotations/__main__.py", line 56, in main
    show_diffs=not args.quiet)
  File "/usr/lib/python3.5/lib2to3/main.py", line 63, in __init__
    super(StdoutRefactoringTool, self).__init__(fixers, options, explicit)
  File "/usr/lib/python3.5/lib2to3/refactor.py", line 698, in __init__
    super(MultiprocessRefactoringTool, self).__init__(*args, **kwargs)
  File "/usr/lib/python3.5/lib2to3/refactor.py", line 210, in __init__
    self.pre_order, self.post_order = self.get_fixers()
  File "/usr/lib/python3.5/lib2to3/refactor.py", line 255, in get_fixers
    fixer = fix_class(self.options, self.fixer_log)
  File "/usr/lib/python3.5/lib2to3/fixer_base.py", line 58, in __init__
    self.compile_pattern()
  File "/usr/lib/python3.5/lib2to3/fixer_base.py", line 67, in compile_pattern
    PC = PatternCompiler()
  File "/usr/lib/python3.5/lib2to3/patcomp.py", line 50, in __init__
    self.grammar = driver.load_grammar(grammar_file)
  File "/usr/lib/python3.5/lib2to3/pgen2/driver.py", line 120, in load_grammar
    logger.info("Generating grammar tables from %s", gt)
  File "/usr/lib/python3.5/logging/__init__.py", line 1279, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib/python3.5/logging/__init__.py", line 1414, in _log
    exc_info, func, extra, sinfo)
  File "/usr/lib/python3.5/logging/__init__.py", line 1384, in makeRecord
    sinfo)
  File "/usr/lib/python3.5/logging/__init__.py", line 269, in __init__
    if (args and len(args) == 1 and isinstance(args[0], collections.Mapping)
  File "/usr/lib/python3.5/abc.py", line 191, in __instancecheck__
    return cls.__subclasscheck__(subclass)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
    return issubclass(cls, self.__extra__)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
    return issubclass(cls, self.__extra__)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
    return issubclass(cls, self.__extra__)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
    return issubclass(cls, self.__extra__)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
    return issubclass(cls, self.__extra__)
  File "/usr/lib/python3.5/abc.py", line 226, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/usr/lib/python3.5/typing.py", line 1081, in __subclasscheck__
[...]
 File "/usr/lib/python3.5/abc.py", line 197, in __subclasscheck__
    if subclass in cls._abc_cache:
RecursionError: maximum recursion depth exceeded

@ilevkivskyi
Copy link
Member Author

@jabdoa2 I don't think that command actually installed typing_extensions (typing is not touched in this PR, this is intentional). I am not a big pip expert, but I think you can just clone, then typing_extensions/src_py3 and run setup.py from there.

@jabdoa2
Copy link

jabdoa2 commented Nov 25, 2017

That pip command should do the same as calling setup.py manually. I can try setup.py tomorrow to be sure.

@ilevkivskyi
Copy link
Member Author

@jabdoa2

That pip command should do the same as calling setup.py manually. I can try setup.py tomorrow to be sure.

I think that command does not install typing_extensions because it runs setup.py from typing, not from the folder I said.

@jabdoa2
Copy link

jabdoa2 commented Nov 25, 2017

Makes sense. Will give it a try

@jabdoa2
Copy link

jabdoa2 commented Nov 26, 2017

Works fine. Thanks for the fix!

@ilevkivskyi
Copy link
Member Author

@gvanrossum If you don't have objections for this, then I will merge this PR soon.

@gvanrossum
Copy link
Member

Go ahead! I didn't try to follow all the details but I agree with the high level idea, and the OP is happy with it.

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

Successfully merging this pull request may close these issues.

typing_extensions crash on Python 3.5.0 - 3.5.2 if used together with collections.abc
4 participants