Skip to content

Instantly share code, notes, and snippets.

"""
`wired` (と、それを使う `pyramid_services`) で
`iface` に `Protocol` を使うと `isinstance` が使えなくなるメモ
たぶんwiredでなくてもクラスに何かを書き込むようなライブラリは
同じ理由で意図した動作にならないんだろう
"""
from typing import Protocol, runtime_checkable
@gjo
gjo / reproduce.sh
Created September 26, 2020 06:21
reproduce pipenv:#4235
#!/bin/bash -x
mkpkg() {
name=$1
shift
deps="$*"
mkdir -p $name/$name
touch $name/$name/__init__.py
cat > $name/setup.py <<EOF
from setuptools import setup
@gjo
gjo / interface_attribute_annotated.py
Last active March 7, 2019 06:50
testing annotated attributes (tests/samples/annotated_attribute.py) with mypy_zope 0.1.3
"""zope.interface provides an attribute with a type annotation for classes
(requres: python 3.6)
"""
import typing
import zope.interface
class IFoo(zope.interface.Interface):
f_str: typing.Text = zope.interface.Attribute('String Attr')
f_str_opt: typing.Optional[typing.Text] = zope.interface.Attribute('Optional String Attr')
@gjo
gjo / annotated_attribute.py
Created March 7, 2019 06:46
testing annotated attributes (tests/samples/annotated_attribute.py) with mypy_zope 0.1.3
"""zope.interface provides an attribute with a type annotation for classes
(requres: python 3.6)
"""
import typing
import zope.interface
class IFoo(zope.interface.Interface):
f_str: typing.Text = zope.interface.Attribute('String Attr')
f_str_opt: typing.Optional[typing.Text] = zope.interface.Attribute('Optional String Attr')
@gjo
gjo / broken_ordering.py
Last active October 17, 2017 09:06
Bad KnowHow of SQLAlchemy
# -*- coding: utf8 -*-
from __future__ import print_function
import sqlalchemy as sa
from sqlalchemy.orm import backref, joinedload, relationship, subqueryload
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
@gjo
gjo / broken_ordering.py
Created October 17, 2017 06:38
Bad KnowHow of SQLAlchemy
# -*- coding: utf8 -*-
from __future__ import print_function
import sqlalchemy as sa
from sqlalchemy.orm import backref, joinedload, relationship, subqueryload
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# -*- coding: utf-8 -*-
# http://flask.pocoo.org/docs/quickstart/#a-minimal-application
# から
# http://flask.pocoo.org/docs/quickstart/#variable-rules
# までを写経していくと
from flask import Flask
app = Flask(__name__)
# -*- coding: utf-8 -*-
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/
# から抜粋
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
@gjo
gjo / is_this_secure.py
Last active December 22, 2015 12:39
Code sample for PyCon APAC 2013 session
# -*- coding: utf-8 -*-
from flask import Flask
from werkzeug.exceptions import NotFound
from jinja2 import Template
import sqlite3
app = Flask(__name__)