Skip to content

Commit

Permalink
backport of eval_str
Browse files Browse the repository at this point in the history
This commit was sponsored by zts, Jason Walker, Steven S., and my
other patrons.  If you want to join them, you can support my work at
https://glyph.im/patrons/.
  • Loading branch information
glyph committed Mar 28, 2024
1 parent aba4fdb commit d5a888b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ repos:
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-eval
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
Expand Down
12 changes: 10 additions & 2 deletions src/dbxs/_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import sys
from contextlib import asynccontextmanager
from inspect import signature
from typing import AsyncContextManager, AsyncIterator, Callable, TypeVar
Expand Down Expand Up @@ -48,10 +49,17 @@ async def userAndPosts(pool: AsyncConnectable, id: UserID) -> str:
# transaction commits here
"""

sig = signature(repositoryType, eval_str=True)
sig = signature(repositoryType)
accessors = {}
for name, parameter in sig.parameters.items(): # pragma: no branch
accessors[name] = accessor(parameter.annotation)
annotation = parameter.annotation
# It would be nicer to do this with signature(..., eval_str=True), but
# that's not available until we require python>=3.10
if isinstance(annotation, str): # pragma: no branch
annotation = eval(
annotation, sys.modules[repositoryType.__module__].__dict__
)
accessors[name] = accessor(annotation)

@asynccontextmanager
async def transactify(acxn: AsyncConnectable) -> AsyncIterator[T]:
Expand Down

0 comments on commit d5a888b

Please sign in to comment.