Skip to content

Commit 7329c50

Browse files
lgtm-com[bot]lgtm-migratormaxfischer2781
authored
Add CodeQL workflow for GitHub code scanning (#94)
* Add CodeQL workflow for GitHub code scanning * removed erroneous 'public' name of private helpers Co-authored-by: LGTM Migrator <[email protected]> Co-authored-by: Max Fischer <[email protected]>
1 parent da9c603 commit 7329c50

File tree

10 files changed

+57
-15
lines changed

10 files changed

+57
-15
lines changed

.github/workflows/codeql.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: "4 9 * * 4"
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ python ]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
queries: +security-and-quality
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2
40+
with:
41+
category: "/language:${{ matrix.language }}"

.github/workflows/unittests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7-
runs-on: ubuntu-latest
7+
runs-on: ubuntu-20.04
88
strategy:
99
matrix:
1010
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.6', 'pypy-3.7']

asyncstdlib/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def awaitify(
9797
) -> Callable[..., Awaitable[T]]:
9898
"""Ensure that ``function`` can be used in ``await`` expressions"""
9999
if iscoroutinefunction(function):
100-
return function # type: ignore
100+
return function
101101
else:
102102
return Awaitify(function)
103103

asyncstdlib/_lrucache.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def cache_discard(self, *args: Any, **kwargs: Any) -> None:
100100
# of just passing in `self`/`cls`/... directly.
101101

102102

103-
@public_module("asyncstdlib.functools")
104103
class LRUAsyncBoundCallable(LRUAsyncCallable[AC]):
105104
"""A :py:class:`~.LRUAsyncCallable` that is bound like a method"""
106105

@@ -293,16 +292,16 @@ def cache__get(
293292
return LRUAsyncBoundCallable(self, instance)
294293

295294

296-
@public_module("asyncstdlib.functools")
297295
class UncachedLRUAsyncCallable(LRUAsyncCallable[AC]):
298296
"""Wrap the async ``call`` to track accesses as for caching/memoization"""
299297

300298
__slots__ = ("__weakref__", "__dict__", "__wrapped__", "__misses", "__typed")
301299

300+
__wrapped__: AC
302301
__get__ = cache__get
303302

304303
def __init__(self, call: AC, typed: bool):
305-
self.__wrapped__ = call # type: ignore
304+
self.__wrapped__ = call
306305
self.__misses = 0
307306
self.__typed = typed
308307

@@ -323,7 +322,6 @@ def cache_discard(self, *args: Any, **kwargs: Any) -> None:
323322
return
324323

325324

326-
@public_module("asyncstdlib.functools")
327325
class MemoizedLRUAsyncCallable(LRUAsyncCallable[AC]):
328326
"""Wrap the async ``call`` with async memoization"""
329327

@@ -337,10 +335,11 @@ class MemoizedLRUAsyncCallable(LRUAsyncCallable[AC]):
337335
"__cache",
338336
)
339337

338+
__wrapped__: AC
340339
__get__ = cache__get
341340

342341
def __init__(self, call: AC, typed: bool):
343-
self.__wrapped__ = call # type: ignore
342+
self.__wrapped__ = call
344343
self.__hits = 0
345344
self.__misses = 0
346345
self.__typed = typed
@@ -377,7 +376,6 @@ def cache_discard(self, *args: Any, **kwargs: Any) -> None:
377376
self.__cache.pop(CallKey.from_call(args, kwargs, typed=self.__typed), None)
378377

379378

380-
@public_module("asyncstdlib.functools")
381379
class CachedLRUAsyncCallable(LRUAsyncCallable[AC]):
382380
"""Wrap the async ``call`` with async LRU caching of finite capacity"""
383381

@@ -392,10 +390,11 @@ class CachedLRUAsyncCallable(LRUAsyncCallable[AC]):
392390
"__cache",
393391
)
394392

393+
__wrapped__: AC
395394
__get__ = cache__get
396395

397396
def __init__(self, call: AC, typed: bool, maxsize: int):
398-
self.__wrapped__ = call # type: ignore
397+
self.__wrapped__ = call
399398
self.__hits = 0
400399
self.__misses = 0
401400
self.__typed = typed

asyncstdlib/_typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"T4",
3939
"T5",
4040
"R",
41+
"C",
4142
"AC",
4243
"HK",
4344
"LT",

asyncstdlib/asynctools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def __init__(self, iterator: Union[AsyncIterator[T], AsyncGenerator[T, S]]):
4949
# running aiter(self).aclose closes the underlying iterator.
5050
self.__anext__ = self._wrapper.__anext__ # type: ignore
5151
if hasattr(iterator, "asend"):
52-
self.asend = iterator.asend # type: ignore
52+
self.asend = iterator.asend
5353
if hasattr(iterator, "athrow"):
54-
self.athrow = iterator.athrow # type: ignore
54+
self.athrow = iterator.athrow
5555

5656
# Py3.6 compatibility
5757
# Use ``(item async for item in iterator)`` inside

asyncstdlib/contextlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
9494
# Use `aclose` to have additional checks for the child to
9595
# handle shutdown properly.
9696
if exc_type is GeneratorExit:
97-
result = await self.gen.aclose()
97+
result = await self.gen.aclose() # type: ignore
9898
else:
9999
result = await self.gen.athrow(exc_type, exc_val, exc_tb)
100100
except StopAsyncIteration as exc:
@@ -439,7 +439,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, tb: Any) -> bool:
439439
self._stitch_context(exc, exc_val, unwind_context)
440440
reraise_exc = True
441441
exc_type, exc_val, tb = type(exc), exc, exc.__traceback__
442-
if reraise_exc:
442+
if reraise_exc and exc_val is not None:
443443
# The __context__ is replaced by a normal `raise`, and only
444444
# preserved by a bare `raise` in an except block.
445445
exc_context = exc_val.__context__

asyncstdlib/heapq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async def merge(
174174
finally:
175175
for itr, _ in iter_heap:
176176
if hasattr(itr.tail, "aclose"):
177-
await itr.tail.aclose() # type: ignore
177+
await itr.tail.aclose()
178178

179179

180180
class ReverseLT(Generic[LT]):

asyncstdlib/itertools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ async def tee_peer(
342342
break
343343
# if we are the last peer, try and close the iterator
344344
if not peers and hasattr(iterator, "aclose"):
345-
await iterator.aclose() # type: ignore
345+
await iterator.aclose()
346346

347347

348348
@public_module(__name__, "tee")

unittests/test_contextlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ async def exit_ge():
185185
try:
186186
yield
187187
except GeneratorExit:
188+
# treat GE as regular exit
188189
pass
189190

190191
with pytest.raises(GeneratorExit):

0 commit comments

Comments
 (0)