astroid
astroid copied to clipboard
option to treat `TYPE_CHECKING` as `True`, or add a separate variable
Current problem
i have some edge cases where a class behaves differently at runtime than what the type checker thinks. here's a super minimal example:
class Foo:
if TYPE_CHECKING:
def __init__(self) -> None:
pass
else:
def __init__(self, value: int) -> None:
pass
a = Foo() # pylint: No value for argument 'value' in constructor (no-value-for-parameter)
in this case i don't want a pylint error here for the same reason i don't want a mypy error.
Desired solution
either:
- option to treat
TYPE_CHECKINGasTrue - add a
PYLINT_LINTINGvariable that works the same way, which is treated asTrueby the linter andFalseat runtime
Additional context
i'm making a ReifiedGeneric class that returns a _ReifiedGenericAlias when __class_getitem__ is called at runtime:
class ReifiedGeneric(Generic[T], metaclass=_ReifiedGenericMetaclass):
__orig_class__: OrigClass
if not TYPE_CHECKING:
def __class_getitem__(cls, item) -> type[ReifiedGeneric[T]]:
generic_alias = super().__class_getitem__(item)
return _ReifiedGenericAlias(
generic_alias.__origin__, generic_alias.__args__
)
long story short, pylint complains here when i don't want it to even know about this _ReifiedGenericAlias class:
class Reified(ReifiedGeneric[T]):
def __init__(self) -> None: # __init__ method from base class '_ReifiedGenericAlias' is not called (super-init-not-called)
print(1)
See: https://github.com/PyCQA/pylint/issues/5637#issuecomment-1006162401
@DetachHead Please use the issue template when filing issues, even if you have opened the issue before. Issues like this are not likely to be taken up by anyone..