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

ImportError: cannot import name 'NoReturn' #1666

Closed
jonathan-s opened this issue Sep 2, 2020 · 9 comments · Fixed by #1668
Closed

ImportError: cannot import name 'NoReturn' #1666

jonathan-s opened this issue Sep 2, 2020 · 9 comments · Fixed by #1668
Labels
good first issue Good for newcomers T: bug Something isn't working

Comments

@jonathan-s
Copy link

jonathan-s commented Sep 2, 2020

Describe the bug A clear and concise description of what the bug is.

Running black in the console generates a traceback.

To Reproduce Steps to reproduce the behavior:
Running black directly in the console gives me the following traceback.

Traceback (most recent call last):
  File "/Users/jonathan/projects/recorded/integrations/splunk/venv/bin/black", line 7, in <module>
    from black import patched_main
  File "/Users/jonathan/projects/recorded/integrations/splunk/venv/lib/python3.6/site-packages/black/__init__.py", line 57, in <module>
    from blib2to3 import pygram, pytree
  File "/Users/jonathan/projects/recorded/integrations/splunk/venv/lib/python3.6/site-packages/blib2to3/pygram.py", line 13, in <module>
    from .pgen2 import driver
  File "/Users/jonathan/projects/recorded/integrations/splunk/venv/lib/python3.6/site-packages/blib2to3/pgen2/driver.py", line 39, in <module>
    from . import grammar, parse, token, tokenize, pgen
  File "/Users/jonathan/projects/recorded/integrations/splunk/venv/lib/python3.6/site-packages/blib2to3/pgen2/pgen.py", line 7, in <module>
    from typing import (
ImportError: cannot import name 'NoReturn'

Expected behavior A clear and concise description of what you expected to happen.

Shouldn't have any error.

Environment (please complete the following information):

  • Version: black (20.8b1)
  • OS and Python version: OSX, python 3.6.1
@jonathan-s jonathan-s added the T: bug Something isn't working label Sep 2, 2020
@JelleZijlstra
Copy link
Collaborator

typing.NoReturn was added in 3.6.2 (https://docs.python.org/3/library/typing.html#typing.NoReturn). I'd accept a PR that falls back to typing_extensions.NoReturn for 3.6.0 and 3.6.1. Maybe it's time to upgrade though :)

@jonathan-s
Copy link
Author

Thanks for the heads up. :) Perhaps an update of the documentation will do? Dropping 3.6.1

@hugovk
Copy link
Contributor

hugovk commented Sep 2, 2020

Please see PR #1668 to update the README, and the black.vim and setup.py checks.

@JelleZijlstra
Copy link
Collaborator

I mildly prefer continuing to support 3.6.0/1 by adding a fallback to typing_extensions.NoReturn, especially since we already require typing-extensions (https://github.com/psf/black/blob/master/setup.py#L78). I could live with dropping support for 3.6.0/1 too, though, if that's what other developers prefer.

@cooperlees
Copy link
Collaborator

I vote either way. I feel 3.6.2 is very accessible these days (with most distros defaulting to > 3.6.2 these days). Since the backport is easy, we already have the dependency and it's only for typing, I see no big reason to not support 3.6.0. But I expect a reason to eventually come to need > 3.6.1 ...

@zsol
Copy link
Collaborator

zsol commented Sep 6, 2020

I feel like given how easy it is to work around this (implementation & maintenance wise), I'd rather not drop support for 3.6.0 and 3.6.1 just because of this issue.

@asottile
Copy link
Contributor

asottile commented Sep 8, 2020

(from experience) when adjusting python_requires>=3.6 to python_requires>=3.6.1 (or whatever) -- you're usually best to make one final release which supports the old versions before dropping such that pip will resolve to that instead of installing a broken thing

as for linting / preventing something like this in the future, I've created a flake8 plugin for this: flake8-typing-imports

@ichard26
Copy link
Collaborator

ichard26 commented Feb 28, 2021

I vote for maintain (technically start supporting) Python 3.6.0 and 3.6.1 since the maintenance cost is minimal. I doubt we'll need to drop 3.6.0/1 for the future, especially since 3.6's EOL is in 10 months. Since I see no real objection to supporting 3.6.0/1, I'll create a counter-proposal PR (the good first issue label did nothing unfortunately).

@ichard26
Copy link
Collaborator

Actually there are some nasty issues on Python 3.6.0:

=================================================================== FAILURES ===================================================================
___________________________________________________ BlackTestCase.test_bpo_33660_workaround ____________________________________________________

self = <tests.test_black.BlackTestCase testMethod=test_bpo_33660_workaround>

    def test_bpo_33660_workaround(self) -> None:
        if system() == "Windows":
            return
    
        # https://bugs.python.org/issue33660
    
        old_cwd = Path.cwd()
        try:
            root = Path("/")
            os.chdir(str(root))
            path = Path("workspace") / "project"
            report = black.Report(verbose=True)
            normalized_path = black.normalize_path_maybe_ignore(path, root, report)
>           self.assertEqual(normalized_path, "workspace/project")
E           AssertionError: 'workspace' != 'workspace/project'
E           - workspace
E           + workspace/project

tests/test_black.py:1800: AssertionError
______________________________________________________ PrimerLibTests.test_process_queue _______________________________________________________

self = <tests.test_primer.PrimerLibTests testMethod=test_process_queue>, mock_stdout = <_io.StringIO object at 0x7f61a2912af8>

    @patch("sys.stdout", new_callable=StringIO)
    @event_loop()
    def test_process_queue(self, mock_stdout: Mock) -> None:
        loop = asyncio.get_event_loop()
        config_path = Path(lib.__file__).parent / "primer.json"
        with patch("black_primer.lib.git_checkout_or_rebase", return_false):
            with TemporaryDirectory() as td:
                return_val = loop.run_until_complete(
>                   lib.process_queue(str(config_path), td, 2)
                )

tests/test_primer.py:183: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/python3.6.0/lib/python3.6/asyncio/base_events.py:466: in run_until_complete
    return future.result()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

config_file = '/home/ichard26/programming/oss/black/env/lib/python3.6/site-packages/black_primer/primer.json', work_path = '/tmp/tmpec7saic8'
workers = 2, keep = False, long_checkouts = False, rebase = False

    async def process_queue(
        config_file: str,
        work_path: Path,
        workers: int,
        keep: bool = False,
        long_checkouts: bool = False,
        rebase: bool = False,
    ) -> int:
        """
        Process the queue with X workers and evaluate results
        - Success is guaged via the config "expect_formatting_changes"
    
        Integer return equals the number of failed projects
        """
>       results = Results()
E       TypeError: __new__() missing 2 required positional arguments: 'stats' and 'failed_projects'

env/lib/python3.6/site-packages/black_primer/lib.py:306: TypeError
=============================================================== warnings summary ===============================================================
tests/test_blackd.py: 14 warnings
  /home/ichard26/programming/oss/black/env/lib/python3.6/site-packages/aiohttp/web_urldispatcher.py:188: DeprecationWarning: Bare functions are deprecated, use async ones
    "Bare functions are deprecated, " "use async ones", DeprecationWarning

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================================================== short test summary info ============================================================
FAILED tests/test_black.py::BlackTestCase::test_bpo_33660_workaround - AssertionError: 'workspace' != 'workspace/project'
FAILED tests/test_primer.py::PrimerLibTests::test_process_queue - TypeError: __new__() missing 2 required positional arguments: 'stats' and '...
======================================= 2 failed, 170 passed, 3 xfailed, 14 warnings in 99.38s (0:01:39) =======================================

For the __new__() missing arguments error, that is because NamedTuple only gained support for default arguments in Python 3.6.1. I'm not sure what's up with PosixPath.resolve() misbehaving on Python 3.6.0 (I don't want to compile 3.6.1 right now so no idea whether it works on that version), but it doesn't seem like something we want to work around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants