Skip to content

Instantly share code, notes, and snippets.

View erickpeirson's full-sized avatar
🟢

Erick erickpeirson

🟢
View GitHub Profile
upstream submit {
server 127.0.0.1:8001;
}
upstream auth {
server 127.0.0.1:8002;
}
server {
listen 8000;
import pandas as pd
from datetime import datetime
from pytz import UTC, timezone
ET = timezone('US/Eastern')
s = pd.Series([datetime.now(UTC)]) # This is the same as a column in your dataframe.
def convert_datetime(dt: datetime) -> datetime:
"""Convert a localized datetime to Eastern time."""
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://foo.qwerty/some/schema#",
"title": "Foo Schema",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"awesome": {
class APIv4(API):
"""JSON Schema draft 4."""
...
def object(self, ctx: AnalyzeTypeContext, schema: Dict[str, Any],
outer: bool = False, **kwargs) -> Type:
"""Generate an annotation for an object, usually a TypedDict."""
properties = schema.get('properties')
import os
import json
class JSONSchemaPlugin(Plugin):
"""Provides support for the JSON Schema as TypedDict."""
JSONSchema = 'jsonschema_typed.types.JSONSchema'
JSONSchemaBase = 'jsonschema_typed.types.JSONSchemaBase'
class JSONSchemaPlugin(Plugin):
"""Provides support for the JSON Schema as TypedDict."""
# I put the placeholder class in a package called `jsonschema_typed`.
JSONSchema = 'jsonschema_typed.types.JSONSchema'
def get_type_analyze_hook(self, fullname: str) -> Optional[Callable]:
"""Produce an analyzer callback if a JSONSchema annotation is found."""
if fullname == self.JSONSchema:
def callback(ctx: AnalyzeTypeContext) -> TypedDictType:
class JSONSchema(dict):
"""Placeholder for JSON schema TypedDict."""
class ThePlugin:
"""My custom plugin for mypy."""
def get_type_analyze_hook(self, fullname: str) -> Optional[Callable[[AnalyzeTypeContext], Type]]:
"""Customize analysis of specific types."""
if fullname == 'somemodule.SomeName':
return analyze_some_name
return None # mypy will just move on without us.
data: JSONSchema['path/to/schema.json'] = json.loads(raw_data)
data['apropertyintheschema'] # OK
data['notintheschema'] # error: TypedDict "FooSchema" has no key 'notintheschema'
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://foo.qwerty/some/schema#",
"title": "A Resource",
"type": "object",
"properties": {
"thiskeyhere": {
"type": "string"
},
"aninteger": {