microsoft / pyright

Static Type Checker for Python
Other
13.15k stars 1.4k forks source link

Allow patterns in execution environments #9022

Closed jvacek closed 1 day ago

jvacek commented 1 day ago

I would like to be able to define a setting that would do something like this:

[pyright.analysis.ignore.pattern-level-settings]
"**/models/**/*.py" = "reportAttributeAccessIssue=false"
"**/views/**/*.py" = "strict, reportPrivateUsage=false"

where the LHS defines a pattern, and the RHS assigns file-level type controls as defined here

This would save me putting # pyright: strict, reportPrivateUsage=false at the top of every single view file 😬

erictraut commented 1 day ago

Thanks for the suggestion, but there are already many ways to configure pyright's type checking rules. Adding yet another mechanism isn't something we're likely to do unless there's really strong demand for it.

If I understand your use case correctly, you should be able to accomplish this with execution environments in your config file. Just specify one execution environment for each of the models and views subdirectories and enable/disable the rules you want for those directories.

jvacek commented 1 day ago

thanks for the prompt reply @erictraut!

Is there any chance these environments could take patterns for the root? My main usecase is that I want target only specific files in a range of dirs.

erictraut commented 1 day ago

Is there any chance these environments could take patterns for the root?

That would deviate from the original intent behind execution environments, but it's something we could consider if there's sufficient demand from pyright users. I don't plan to add such a feature at this time, but if this issue gathers enough upvotes, I'd consider re-opening it in the future.

jvacek commented 1 day ago

Hmm I would then consider re-creating the issue with a better name in that case, would that be ok?

erictraut commented 17 hours ago

You should be able to edit the issue title.