Skip to content

Commit

Permalink
Enable Error rules
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Sep 20, 2023
1 parent 8193e23 commit 1a67d10
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
8 changes: 4 additions & 4 deletions notes-to-self/how-does-windows-so-reuseaddr-work.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def table_entry(mode1, bind_type1, mode2, bind_type2):
# default | wildcard | INUSE | Success | ACCESS | Success | INUSE | Success
)

for i, mode1 in enumerate(modes):
for j, bind_type1 in enumerate(bind_types):
for mode1 in modes:
for bind_type1 in bind_types:
row = []
for k, mode2 in enumerate(modes):
for l, bind_type2 in enumerate(bind_types):
for mode2 in modes:
for bind_type2 in bind_types:
entry = table_entry(mode1, bind_type1, mode2, bind_type2)
row.append(entry)
# print(mode1, bind_type1, mode2, bind_type2, entry)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ target-version = "py38"
respect-gitignore = true
fix = true

line-length = 170

# The directories to consider when resolving first vs. third-party imports.
# Does not control what files to include/exclude!
src = ["trio", "notes-to-self"]

select = [
"E", # Error
"F", # pyflakes
"I", # isort
"YTT", # flake8-2020
Expand All @@ -28,6 +31,7 @@ extend-ignore = [
'F403', # undefined-local-with-import-star
'F405', # undefined-local-with-import-star-usage
'F821', # undefined-name
'E402', # module-import-not-at-top-of-file (usually OS-specific)
]

include = ["*.py", "*.pyi", "**/pyproject.toml"]
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def call(self, hookname: str, *args: Any) -> None:
for instrument in list(self[hookname]):
try:
getattr(instrument, hookname)(*args)
except:
except BaseException:
self.remove_instrument(instrument)
INSTRUMENT_LOGGER.exception(
"Exception raised when calling %r on instrument %r. "
Expand Down
5 changes: 4 additions & 1 deletion trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,10 @@ class GuestState:
run_sync_soon_not_threadsafe: Callable[[Callable[[], object]], object] = attr.ib()
done_callback: Callable[[Outcome[Any]], object] = attr.ib()
unrolled_run_gen: Generator[float, EventResult, None] = attr.ib()
_value_factory: Callable[[], Value[Any]] = lambda: Value(None)

def _value_factory() -> Value[Any]:

Check failure on line 1489 in trio/_core/_run.py

View workflow job for this annotation

GitHub Actions / Ubuntu (3.8, check formatting)

Mypy-Linux+Mac+Windows

trio/_core/_run.py:(1489:5 - 1489:5): Method must have at least one argument. Did you forget the "self" argument? [misc]
return Value(None)

unrolled_run_next_send: Outcome[Any] = attr.ib(factory=_value_factory)

def guest_tick(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ async def test_Nursery_init() -> None:
async def test_Nursery_private_init() -> None:
# context manager creation should not raise
async with _core.open_nursery() as nursery:
assert False == nursery._closed
assert not nursery._closed


def test_Nursery_subclass() -> None:
Expand Down
7 changes: 4 additions & 3 deletions trio/_subprocess_platform/kqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ async def wait_child_exiting(process: "_subprocess.Process") -> None:
# I verified this value against both Darwin and FreeBSD
KQ_NOTE_EXIT = 0x80000000

make_event = lambda flags: select.kevent(
process.pid, filter=select.KQ_FILTER_PROC, flags=flags, fflags=KQ_NOTE_EXIT
)
def make_event(flags: int) -> select.kevent:
return select.kevent(
process.pid, filter=select.KQ_FILTER_PROC, flags=flags, fflags=KQ_NOTE_EXIT
)

try:
kqueue.control([make_event(select.KQ_EV_ADD | select.KQ_EV_ONESHOT)], 0)
Expand Down
2 changes: 1 addition & 1 deletion trio/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class Condition(AsyncContextManagerMixin):
def __init__(self, lock: Lock | None = None):
if lock is None:
lock = Lock()
if not type(lock) is Lock:
if type(lock) is not Lock:
raise TypeError("lock must be a trio.Lock")
self._lock = lock
self._lot = trio.lowlevel.ParkingLot()
Expand Down
12 changes: 6 additions & 6 deletions trio/_tests/test_highlevel_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,21 @@ async def accept(self):
]
)

l = SocketListener(fake_listen_sock)
listener = SocketListener(fake_listen_sock)

with assert_checkpoints():
s = await l.accept()
assert s.socket is fake_server_sock
stream = await listener.accept()
assert stream.socket is fake_server_sock

for code in [errno.EMFILE, errno.EFAULT, errno.ENOBUFS]:
with assert_checkpoints():
with pytest.raises(OSError) as excinfo:
await l.accept()
await listener.accept()
assert excinfo.value.errno == code

with assert_checkpoints():
s = await l.accept()
assert s.socket is fake_server_sock
stream = await listener.accept()
assert stream.socket is fake_server_sock


async def test_socket_stream_works_when_peer_has_already_closed():
Expand Down
2 changes: 1 addition & 1 deletion trio/_tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def test_open_signal_receiver_no_starvation() -> None:
# Clear out the last signal so that it doesn't get redelivered
while get_pending_signal_count(receiver) != 0:
await receiver.__anext__()
except: # pragma: no cover
except BaseException: # pragma: no cover
# If there's an unhandled exception above, then exiting the
# open_signal_receiver block might cause the signal to be
# redelivered and give us a core dump instead of a traceback...
Expand Down
11 changes: 8 additions & 3 deletions trio/_tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Since Windows has very few command-line utilities generally available,
# all of our subprocesses are Python processes running short bits of
# (mostly) cross-platform code.
def python(code):
def python(code: str) -> list[str]:
return [sys.executable, "-u", "-c", "import sys; " + code]


Expand All @@ -53,9 +53,14 @@ def python(code):
CAT = python("sys.stdout.buffer.write(sys.stdin.buffer.read())")

if posix:
SLEEP = lambda seconds: ["/bin/sleep", str(seconds)]

def SLEEP(seconds: int) -> list[str]:
return ["/bin/sleep", str(seconds)]

else:
SLEEP = lambda seconds: python(f"import time; time.sleep({seconds})")

def SLEEP(seconds: int) -> list[str]:
return python(f"import time; time.sleep({seconds})")

Check warning on line 63 in trio/_tests/test_subprocess.py

View check run for this annotation

Codecov / codecov/patch

trio/_tests/test_subprocess.py#L62-L63

Added lines #L62 - L63 were not covered by tests


def got_signal(proc, sig):
Expand Down

0 comments on commit 1a67d10

Please sign in to comment.