PyCQA / flake8-pyi

A plugin for Flake8 that provides specializations for type hinting stub files
MIT License
73 stars 23 forks source link

`Y016` doesn't account for single member unions #484

Open tusharsadhwani opened 6 months ago

tusharsadhwani commented 6 months ago

For code like:

from typing import Union
x: Union[int, Union[int]]

Y016 should be raised but isn't.

JelleZijlstra commented 6 months ago

Seems more important to raise an error saying that the nested union is useless.

tusharsadhwani commented 6 months ago

saying that the nested union is useless

More like a single member union Union[X] can always be replaced by X, I believe.

I'd be up for writing that rule. Y067? Does that work?

JelleZijlstra commented 6 months ago

I guess it's sort of redundant with Y037, which tells you to use | instead of Union. I wouldn't really be opposed to a PR here but I'm not convinced there's a serious problem our existing checks don't catch.