Fix SLOT002 (subclasses of collections.namedtuple() should define `__slots__`)

This commit is contained in:
Adam Turner
2023-08-13 22:32:34 +01:00
parent e73300b829
commit 1fae1470a4
2 changed files with 8 additions and 4 deletions

View File

@@ -274,8 +274,6 @@ ignore = [
"SIM115", # use context handler for opening files "SIM115", # use context handler for opening files
"SIM117", # use single 'with' statement "SIM117", # use single 'with' statement
"SIM118", # use key in dict not key in dict.keys() "SIM118", # use key in dict not key in dict.keys()
# flake8-slots
"SLOT002", # Subclasses of collections.namedtuple() should define __slots__
# flake8-self # flake8-self
"SLF001", # private member accessed "SLF001", # private member accessed
# flake8-print # flake8-print

View File

@@ -2,7 +2,6 @@
import json import json
import warnings import warnings
from collections import namedtuple
from io import BytesIO from io import BytesIO
import pytest import pytest
@@ -12,12 +11,19 @@ from docutils.parsers import rst
from sphinx.search import IndexBuilder from sphinx.search import IndexBuilder
class DummyEnvironment(namedtuple('DummyEnvironment', ['version', 'domains'])): class DummyEnvironment:
def __init__(self, version, domains):
self.version = version
self.domains = domains
def __getattr__(self, name): def __getattr__(self, name):
if name.startswith('_search_index_'): if name.startswith('_search_index_'):
setattr(self, name, {}) setattr(self, name, {})
return getattr(self, name, {}) return getattr(self, name, {})
def __str__(self):
return f'DummyEnvironment({self.version!r}, {self.domains!r})'
class DummyDomain: class DummyDomain:
def __init__(self, data): def __init__(self, data):