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

Possible warning bug? #253

Closed
sdimovv opened this issue Apr 28, 2022 · 2 comments
Closed

Possible warning bug? #253

sdimovv opened this issue Apr 28, 2022 · 2 comments

Comments

@sdimovv
Copy link

sdimovv commented Apr 28, 2022

Describe the bug
I am running typeguard with pytest and get the following warning at the end:

======================================================================= warnings summary =======================================================================
.nox/typeguard-3-10-4/lib/python3.10/site-packages/typeguard/__init__.py:1027
  /path/to/dir/.nox/typeguard-3-10-4/lib/python3.10/site-packages/typeguard/__init__.py:1027: UserWarning: no code associated -- not typechecking click.core.<Command main>
    warn('no code associated -- not typechecking {}'.format(function_name(func)))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================= 1 passed, 1 warning in 0.02s =================================================================

To Reproduce
Have a function like this:

import click
from . import __version__

@click.command()
@click.version_option(version=__version__)
def main() -> None:
    """Hello description."""
    click.echo("Hello, world!")

And test like this:

from my_package.cli import console

import click.testing
import pytest


@pytest.fixture
def cli_runner():
    """Return Click test runner."""
    return click.testing.CliRunner()


def test_main_succeeds(cli_runner) -> None:
    """Test main exists withtout errors."""
    result = cli_runner.invoke(console.main)
    assert result.exit_code == 0 

The above snippets should produce the warning when tested with pytest.

Expected behavior
No warning

Additional context
What leads me to believe this might be a bug is that if I change the function like so:

import click

from . import __version__


@click.command()
@click.version_option(version=__version__)
def main(): ############## Notice no "-> None:"
    """Hello description."""
    click.echo("Hello, world!")

The warning disapears.

I tried googling around for the warning but I could not find anything useful. Hopefully this is really a bug and not just me not understanding how to use this tool.

@serixscorpio
Copy link

I think this warning is a fix (#190) to highlight limitations when using click and typeguard instead of treating it as an error. #191 (comment) explains the issue in detail.

@agronholm
Copy link
Owner

Yeah, not a bug, it's just how click seems to work.

@agronholm agronholm closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2023
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

No branches or pull requests

3 participants