Created
October 6, 2020 23:02
-
-
Save karlicoss/dcb5ecc446029f0fb9c92343a6744f63 to your computer and use it in GitHub Desktop.
sqlalchemy + typing + loggger WTF????
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### NOTE: you need to keep hack_logger.py and main.py in separate files, otherwise it's not reproducing | |
### hack_logger.py | |
# NOTE: if you comment this out, it works fine | |
import typing | |
def enabled_for(*args, **kwargs): | |
return True | |
import logging | |
logger = logging.getLogger('whatever') | |
# NOTE: if you comment this out, it works fine | |
logger.isEnabledFor = enabled_for | |
### | |
### main.py | |
from typing import List | |
from sqlalchemy import Column | |
# NOTE: if you comment this out, it works fine | |
_what_could_possibly_go_wrong: List[Column] = [] | |
import hack_logger | |
def it(): | |
from sqlalchemy import create_engine | |
engine = create_engine('sqlite:////tmp/test.sqlite') | |
with engine.connect() as conn: | |
conn.execute('DROP TABLE IF EXISTS test') | |
conn.execute('CREATE TABLE IF NOT EXISTS test (value INT)') | |
with conn.begin(): | |
for i in range(5): | |
conn.execute(f'INSERT INTO test VALUES ({i})') | |
yield i | |
from functools import lru_cache | |
# NOTE: if you remove lcu_cache, it works fine | |
@lru_cache(1) | |
def itc(): | |
return it() | |
next(itc()) | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
Expected: the exception is maybe sort of expected considering that
GeneratorExit
isn't really handled and all thelru_cache
+ generator madness, but wtf withlogging
andtyping
stuff??Python:
3.8.2
SQLAlchemy:
1.3.18