ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Linter: Add warning when attempting to set module attributes

Open tomasalagoa opened this issue 1 year ago • 3 comments

As mentioned in https://lwn.net/Articles/943619/ some developers had an issue distinguishing between a module object and a context object from the module

import numpy as np
import mpmath as mp  # should be from mpmath import mp
mp.dps = 50

This led to an attempt to change the behavior of how Python handled __setattr__ for module objects but was rejected due to poor performance, though I believe it could be a linter rule in ruff.

I've tried to do this but cannot figure out how to get a list of imported modules at runtime, though maybe the rule could be directed only towards the mp module alias.

tomasalagoa avatar Sep 20 '23 11:09 tomasalagoa