Open
Description
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_CHECKING
asTrue
- add a
PYLINT_LINTING
variable that works the same way, which is treated asTrue
by the linter andFalse
at 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)