mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.18k stars 1.89k forks source link

Relax typing strictness for Plot.theme #3682

Closed michaelquinn32 closed 2 months ago

michaelquinn32 commented 2 months ago

Plot.theme currently accepts a dict[str, Any], which unfortunately throws a pytype typing error when passed another similar mapping, like an immutable dict.

def accepts_dict(d: dict[str, Any]) -> None:
    print(d)

accepts_dict(immutabledict.immutabledict({'a': 1}))
# Error: Function accepts_dict was called with the wrong arguments [wrong-arg-types]
#        Expected: (d: Dict[str, Any], ...)
#        Actually passed: (d: immutabledict.immutabledict[nothing, nothing])

Using collections.abc.Mapping doesn't throw an error.

from collections.abc import Mapping

def accepts_mapping(d: Mappingf[str, Any]) -> None:
    print(d)

accepts_mapping(immutabledict.immutabledict({'a': 1}))

Would you mind relaxing the type specificity for this? Thanks!

mwaskom commented 2 months ago

Yeah that makes sense.