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

Is it possible to scope rules to disable them for specific aspects of the codebase? #307

Open
amitkparekh opened this issue Apr 17, 2024 · 4 comments

Comments

@amitkparekh
Copy link

amitkparekh commented Apr 17, 2024

Is it possible to disable a specific rule for a specific subfolder/package/module? I tried to look at the configuration options for pyright itself and I couldn't see it.

For my current project, I am using Typer/Click to make it easier to have explicit entrypoints. For one of the function args, I have annotated it to be int | None and defaulting to None. Here's an example:

def command(
    *, 
    my_option: Annotated[
        Optional[int], typer.Option(min=0, max=10)
    ] = None,
) -> None: ...

Notably, I used Optional[int] instead of int | None because Typer/Click don't support union types and I'm guessing it's not a priority to support.

Currently, basedpyright flags this as reportDeprecated, which is definitely true. But to do what I need, I don't have a choice.

I don't mind throwing a # noqa at it, but I have a bunch of entrypoint functions where this occurs and adding the ignore every single time is quite cumbersome. I know it's technically wrong, but as it's localised to this very specific situation/aspect of my codebase, I just let it be and got on with it.

I don't want to disable the rule project-wide (I like strict), but that's what I've needed to do. Do you have any thoughts on how I could handle this?

<3 this project.

@DetachHead
Copy link
Owner

i thought i already raised an issue for this but i can't find it lol.

im thinking we do this by supporting diagnostic severity overrides in executionEnvironments, for example:

executionEnvironments = [
  { root = "src/foo", reportDeprecated = false },
  { root = "src/bar", reportImplicitRelativeImport = false },
]

@amitkparekh
Copy link
Author

amitkparekh commented Apr 17, 2024

Ah right! I thought that was only for literal environments like Linux vs Mac etc! I didn't realise it did this too!!! I just tried it and it doesn't seem to work? I added the following to my TOML. (Sorry I misread!)

This is totally top of my "basedmpy features" list!

@DetachHead
Copy link
Owner

idk why pyright doesn't support it when mypy does. it's not even exclusive to basedmypy lol

@DetachHead
Copy link
Owner

in the mean time a workaround that should work in your case is using ruff to report deprecated type annotations instead using the pyupgrade rules, since ruff supports per-file ignores

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

No branches or pull requests

2 participants