Skip to content

Instantly share code, notes, and snippets.

View stroxler's full-sized avatar

Steven Troxler stroxler

  • Meta Platforms
  • San Francisco
View GitHub Profile
@stroxler
stroxler / how_dns_works.org
Created August 17, 2022 16:46
How DNS works

Web: DNS

A quick introduction to DNS

DNS at a glance

In one sentence, I’d say that DNS is a chain-of-trust system for configuring

@stroxler
stroxler / TypedDict_extra_keys.org
Created March 16, 2022 02:29
TypedDict: how should we handle extra keys?
@stroxler
stroxler / notes.md
Created February 18, 2022 16:29
Notes on Duckling internals

About this guide

This is a very rough set of notes taken in 2022 to help engineers understand the logic as well as the nontrivial Haskell concepts (e.g. GHC extensions) embodied in that logic.

It is not an official guide from the Duckling authors, and there are likely at least a few errors.

These notes only cover the core Duckling engine, not any logic specific to a specific Dimension. Most dimensions are relatively straightforward, but some are quite complicated - particularly Time - and these notes do not cover those.

The layers we interact with: debug and analyze

@stroxler
stroxler / resources.org
Last active January 24, 2022 21:50
The Most Discoverable Python Typing Tutorials, Etc (circa 2022/01)

This gist is a collection of all the easy-to-find online resources for using typed python as of 2022/01. I collected these notes for two reasons:

  • As an aside in an extensive python-dev typing discussion, Guido mentioned that it would be helpful
  • There’s an active but very slow-moving effort to write official python type system docs in python/typing, and I figured having an easy to skim list of the best existing discussions would be handy.

The official documentation

@stroxler
stroxler / (1) classes.py
Last active January 21, 2022 04:03
How might `inspect.signature_of_type` work?
class Dog:
def __init__(self, color: str) -> None:
self.color = color
def __call__(self, command: str) -> None:
print("Dog will now " + command)
inspect.signature(Dog("brown")) == inspect.signature(Dog) # False
inspect.signature(Dog("brown")) == inspect.signature_of_type(Dog) # True

Considering tweaks to parentheses rules for PEP 677

This gist contains

  • A description of some major concerns I have about adding -> as a legal top-level operator in type expressions.
  • Discussion of solutions that involve requiring parentheses around callable types.
  • Two files of examples of proposed alternative syntax
    • First, a comparison of the current syntax to requiring parentheses both around the args list (as we do now) and around the entire type.
@stroxler
stroxler / full_vs_args_only.py
Last active December 22, 2021 13:53
Comparing rules for parentheses in arrow callable syntax (PEP 677)
# A quick example to illustrate the two syntaxes
def f(x: str, y: int) -> bool: ...
f: ((str, int) -> bool) # full parentheses syntax
f: (str, int) -> bool # args only parentheses
# Now, some samples from typeshed (I abbreviated a few args lists so that it's easier to find the relevant part)
@stroxler
stroxler / callable-type-vs-union.md
Last active December 16, 2021 22:33
Examples of callable type vs union confusion
  1. We can't naively union a callable type with another type:
union_of_callables: (int) -> str | (bool) -> str  # Syntax error!

# Needs extra parens; Not intuitive or user-friendly.
union_of_callable2: ((int) -> str) | ((bool) -> str)

# Simpler and can be easily split into multiple lines, as Никита mentioned.
@stroxler
stroxler / Callable_examples.md
Last active June 16, 2021 21:58
Examples of Callable

Some existing Callable types from github

Using the most restrictive full-stub syntax, here's how we'd express a few Callable types:

# from functools.pyi
f0: Callable[[_T1, _T2], S)
f0: (t1: _T1, t2: _T2, /) -> S

# from shapeflow/api.py
f1: Callable[[Optional[int], np.ndarray], stream_image]