Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any Type Summary #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,081 changes: 3,081 additions & 0 deletions ats24/ACM-Reference-Format.bst

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions ats24/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fast:
pdflatex -shell-escape paper

full: fast
bibtex paper
pdflatex -shell-escape paper
pdflatex -shell-escape paper

7 changes: 7 additions & 0 deletions ats24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

### Prompt
Write an initial report on the preliminary findings.

#### Details
We should produce a report as an artifact of our findings, this can serve as the basis for writing a paper on the subject, but we don’t reasonably expect that the paper will be completed within twelve weeks.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k+kn}{import} \PYG{n+nn}{types}\PYG{p}{;} \PYG{k+kn}{from} \PYG{n+nn}{typing} \PYG{k+kn}{import} \PYG{n}{Any} \PYG{c+c1}{\PYGZsh{} the dynamic type in Python}

\PYG{k}{def} \PYG{n+nf}{addPrice}\PYG{p}{(}\PYG{n+nb+bp}{cls}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:} \PYG{c+c1}{\PYGZsh{} mixin, add method to class}
\PYG{n+nb+bp}{cls}\PYG{o}{.}\PYG{n}{price} \PYG{o}{=} \PYG{n}{types}\PYG{o}{.}\PYG{n}{MethodType}\PYG{p}{(}\PYG{k}{lambda} \PYG{n+nb+bp}{self}\PYG{p}{:} \PYG{l+m+mi}{99}\PYG{p}{,} \PYG{n+nb+bp}{cls}\PYG{p}{)}
\PYG{k}{return} \PYG{n+nb+bp}{cls}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} module A}
\PYG{k+kd}{local} \PYG{n}{A} \PYG{o}{=} \PYG{n+nb}{require}\PYG{p}{(}\PYG{n}{script}\PYG{p}{.}\PYG{n}{B}\PYG{p}{)}

\PYG{c+c1}{\PYGZhy{}\PYGZhy{} module B}
\PYG{k+kd}{local} \PYG{n}{B} \PYG{o}{=} \PYG{n+nb}{require}\PYG{p}{(}\PYG{n}{script}\PYG{p}{.}\PYG{n}{A}\PYG{p}{)} \PYG{p}{::} \PYG{n+nl}{any} \PYG{c+c1}{\PYGZhy{}\PYGZhy{} cyclic dependency fixed with any}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Car} \PYG{o}{=} \PYG{n}{TypeVar}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}Car\PYGZsq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}\PYGZsh{} car is unbounded}
\PYG{n}{Traffic} \PYG{o}{=} \PYG{n}{Union}\PYG{p}{[}\PYG{n}{Car}\PYG{p}{,} \PYG{n}{List}\PYG{p}{[}\PYG{l+s+s1}{\PYGZsq{}Traffic\PYGZsq{}}\PYG{p}{]]}

\PYG{k}{def} \PYG{n+nf}{count\PYGZus{}cars}\PYG{p}{(}\PYG{n}{x}\PYG{p}{:} \PYG{n}{Traffic}\PYG{p}{,} \PYG{n}{car}\PYG{p}{:} \PYG{n}{Car}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{List}\PYG{p}{):}
\PYG{n}{x}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{car}\PYG{p}{)}
\PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}

\PYG{n}{count\PYGZus{}cars}\PYG{p}{([}\PYG{l+s+s2}{\PYGZdq{}FJ40\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}Baja Buggy\PYGZdq{}}\PYG{p}{],} \PYG{l+m+mi}{5}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}mypy: ok}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{BinaryIO}\PYG{p}{(}\PYG{n}{IO}\PYG{p}{[}\PYG{n+nb}{bytes}\PYG{p}{]):}
\PYG{n+nd}{@abstractmethod}
\PYG{k}{def} \PYG{n+nf}{write}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{s}\PYG{p}{:} \PYG{n}{Union}\PYG{p}{[}\PYG{n+nb}{bytes}\PYG{p}{,} \PYG{n+nb}{bytearray}\PYG{p}{])} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{pass}

\PYG{k}{class} \PYG{n+nc}{FileOpener}\PYG{p}{(}\PYG{n}{BinaryIO}\PYG{p}{):}
\PYG{k}{def} \PYG{n+nf}{write}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{s}\PYG{p}{:} \PYG{n+nb}{bytes}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:} \PYG{c+c1}{\PYGZsh{} type: ignore[override]}
\PYG{k}{return} \PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{fdesc}\PYG{o}{.}\PYG{n}{write}\PYG{p}{(}\PYG{n}{s}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Car} \PYG{o}{=} \PYG{n}{TypeVar}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}Car\PYGZsq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} car is unconstrained / unbounded}
\PYG{n}{Traffic} \PYG{o}{=} \PYG{n}{Union}\PYG{p}{[}\PYG{n}{Car}\PYG{p}{,} \PYG{n}{List}\PYG{p}{[}\PYG{l+s+s1}{\PYGZsq{}Traffic\PYGZsq{}}\PYG{p}{]]}

\PYG{k}{def} \PYG{n+nf}{count\PYGZus{}cars}\PYG{p}{(}\PYG{n}{x}\PYG{p}{:} \PYG{n}{Traffic}\PYG{p}{,} \PYG{n}{car}\PYG{p}{:} \PYG{n}{Car}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{List}\PYG{p}{):}
\PYG{n}{x}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{car}\PYG{p}{)}
\PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}

\PYG{n}{count\PYGZus{}cars}\PYG{p}{([}\PYG{l+s+s2}{\PYGZdq{}FJ40\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}Baja Buggy\PYGZdq{}}\PYG{p}{],} \PYG{l+m+mi}{5}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} NOT a type error}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZsh{} textual: https://github.com/Textualize/textual}
\PYG{n+nd}{@lru\PYGZus{}cache}\PYG{p}{(}\PYG{n}{maxsize}\PYG{o}{=}\PYG{l+m+mi}{2048}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{\PYGZus{}count\PYGZus{}parameters}\PYG{p}{(}\PYG{n}{func}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{[}\PYG{n}{Any}\PYG{p}{,} \PYG{n}{Any}\PYG{p}{])} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{signature}\PYG{p}{(}\PYG{n}{func}\PYG{p}{)}\PYG{o}{.}\PYG{n}{parameters}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}discount}\PYG{p}{(}\PYG{n}{item}\PYG{p}{:} \PYG{n}{Dict}\PYG{p}{[}\PYG{n+nb}{str}\PYG{p}{,} \PYG{n}{Any}\PYG{p}{])} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{if} \PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}} \PYG{o+ow}{in} \PYG{n}{item}\PYG{p}{:}
\PYG{n}{discount} \PYG{o}{=} \PYG{n}{item}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}}\PYG{p}{]} \PYG{o}{*} \PYG{l+m+mf}{0.15}
\PYG{k}{return} \PYG{n}{item}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}}\PYG{p}{]} \PYG{o}{\PYGZhy{}} \PYG{n}{discount}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Dict}\PYG{p}{[}\PYG{n}{T1}\PYG{p}{,} \PYG{n}{T2}\PYG{p}{]}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 1}
\PYG{n}{export} \PYG{n+nb}{type} \PYG{n}{AnyFunction} \PYG{o}{=} \PYG{p}{()}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{p}{(} \PYG{n}{any}\PYG{p}{)}
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 2}
\PYG{n+nb}{type} \PYG{n}{Callback} \PYG{o}{=} \PYG{p}{(...}\PYG{n}{any}\PYG{err}{?}\PYG{p}{)}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{p}{(} \PYG{p}{...}\PYG{n}{any}\PYG{err}{?}\PYG{p}{)}
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 3}
\PYG{n}{export} \PYG{n+nb}{type} \PYG{n}{Table} \PYG{o}{=} \PYG{p}{\PYGZob{}[}\PYG{n}{any}\PYG{p}{]:} \PYG{n}{any}\PYG{p}{\PYGZcb{}}

\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{TypeVar}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}Car\PYGZsq{}}\PYG{p}{,} \PYG{n}{bound}\PYG{o}{=}\PYG{n}{AnyStr}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Shape}\PYG{p}{:}
\PYG{k}{def} \PYG{n+nf}{move}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{dist}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{position} \PYG{o}{+=} \PYG{n}{dist}
\PYG{k}{return} \PYG{n+nb+bp}{self}

\PYG{k}{class} \PYG{n+nc}{Circle}\PYG{p}{(}\PYG{n}{Shape}\PYG{p}{):}
\PYG{k}{pass}

\PYG{n}{Circle}\PYG{p}{()}\PYG{o}{.}\PYG{n}{move}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}type: Any}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZsh{}\PYGZsh{} wandb: https://github.com/wandb/wandb}
\PYG{k}{def} \PYG{n+nf+fm}{\PYGZus{}\PYGZus{}getattr\PYGZus{}\PYGZus{}}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{key}\PYG{p}{:} \PYG{n+nb}{str}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:}
\PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{key}\PYG{o}{.}\PYG{n}{startswith}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}\PYGZus{}\PYGZdq{}}\PYG{p}{):}
\PYG{k}{raise} \PYG{n}{wandb}\PYG{o}{.}\PYG{n}{Error}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}...\PYGZdq{}}\PYG{p}{)}
\PYG{k}{else}\PYG{p}{:}
\PYG{k}{raise} \PYG{n+ne}{AttributeError}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf+fm}{\PYGZus{}\PYGZus{}init\PYGZus{}\PYGZus{}}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{value} \PYG{p}{:} \PYG{n}{Any}\PYG{p}{,} \PYG{n}{found} \PYG{p}{:} \PYG{n+nb}{bool}\PYG{p}{):}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{found} \PYG{p}{:} \PYG{n+nb}{bool} \PYG{o}{=} \PYG{n}{found}
\PYG{k}{if} \PYG{n}{found}\PYG{p}{:}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{value} \PYG{o}{=} \PYG{n+nb}{int}\PYG{p}{(}\PYG{n}{value}\PYG{p}{)}
\PYG{k}{else}\PYG{p}{:}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{value} \PYG{o}{=} \PYG{l+s+s1}{\PYGZsq{}.\PYGZsq{}}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{eq}\PYG{p}{(}\PYG{n}{a}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{,} \PYG{n}{b}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{bool}\PYG{p}{:}
\PYG{k}{return} \PYG{n}{a} \PYG{o}{==} \PYG{n}{b}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 1}
\PYG{n}{export} \PYG{n+nb}{type} \PYG{n}{AnyFunction} \PYG{o}{=} \PYG{p}{()}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{p}{(} \PYG{n}{any}\PYG{p}{)}
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 2}
\PYG{n+nb}{type} \PYG{n}{Callback} \PYG{o}{=} \PYG{p}{(...}\PYG{n}{any}\PYG{err}{?}\PYG{p}{)}\PYG{o}{\PYGZhy{}\PYGZgt{}}\PYG{p}{(} \PYG{p}{...}\PYG{n}{any}\PYG{err}{?}\PYG{p}{)}
\PYG{c+c1}{\PYGZhy{}\PYGZhy{} 3}
\PYG{n}{export} \PYG{n+nb}{type} \PYG{n}{Table} \PYG{o}{=} \PYG{p}{\PYGZob{}[}\PYG{n}{any}\PYG{p}{]:} \PYG{n}{any}\PYG{p}{\PYGZcb{}}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Parent}\PYG{p}{():}
\PYG{k}{def} \PYG{n+nf}{something}\PYG{p}{(}\PYG{n}{x}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{):}
\PYG{k}{pass}

\PYG{k}{class} \PYG{n+nc}{Super}\PYG{p}{(}\PYG{n}{Parent}\PYG{p}{):}
\PYG{k}{def} \PYG{n+nf}{something}\PYG{p}{(}\PYG{n}{x}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{):} \PYG{c+c1}{\PYGZsh{}type: ignore[override]}
\PYG{k}{pass}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Car}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Function}\PYG{p}{(}\PYG{n}{\PYGZus{}C}\PYG{o}{.}\PYG{n}{\PYGZus{}FunctionBase}\PYG{p}{):}
\PYG{n+nd}{@staticmethod}
\PYG{k}{def} \PYG{n+nf}{backward}\PYG{p}{(}\PYG{n}{ctx}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{,} \PYG{o}{*}\PYG{n}{grad\PYGZus{}outputs}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:}
\PYG{k}{raise} \PYG{n+ne}{NotImplementedError}\PYG{p}{(}
\PYG{l+s+s2}{\PYGZdq{}You must implement your custom autograd.Function\PYGZdq{}}
\PYG{p}{)}

\PYG{k}{class} \PYG{n+nc}{fake\PYGZus{}quantize\PYGZus{}function}\PYG{p}{(}\PYG{n}{Function}\PYG{p}{):}
\PYG{n+nd}{@staticmethod}
\PYG{k}{def} \PYG{n+nf}{backward}\PYG{p}{(}\PYG{n}{ctx}\PYG{p}{,} \PYG{n}{grad\PYGZus{}output}\PYG{p}{:} \PYG{n}{Tensor}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Tensor}\PYG{p}{:}
\PYG{k}{return} \PYG{n}{grad\PYGZus{}output} \PYG{o}{*} \PYG{n}{ctx}\PYG{o}{.}\PYG{n}{saved\PYGZus{}tensors}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{validate\PYGZus{}stat}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable}\PYG{p}{:}
\PYG{k}{def} \PYG{n+nf}{string\PYGZus{}fn}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{:} \PYG{n+nb}{str}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable}\PYG{p}{:}
\PYG{n}{stat} \PYG{o}{=} \PYG{n}{string\PYGZus{}to\PYGZus{}stat}\PYG{p}{(}\PYG{n}{stat}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{fn}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{string\PYGZus{}fn}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{TypeVar}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}Car\PYGZsq{}}\PYG{p}{,} \PYG{n+nb}{str}\PYG{p}{,} \PYG{n+nb}{bytes}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{get\PYGZus{}discount}\PYG{p}{(}\PYG{n}{item}\PYG{p}{:} \PYG{n}{Dict}\PYG{p}{[}\PYG{n+nb}{str}\PYG{p}{,} \PYG{n}{Any}\PYG{p}{])} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{if} \PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}} \PYG{o+ow}{in} \PYG{n}{item}\PYG{p}{:}
\PYG{n}{discount} \PYG{o}{=} \PYG{n}{item}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}}\PYG{p}{]} \PYG{o}{*} \PYG{l+m+mf}{0.15}
\PYG{k}{return} \PYG{n}{item}\PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}price\PYGZdq{}}\PYG{p}{]} \PYG{o}{\PYGZhy{}} \PYG{n}{discount}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf+fm}{\PYGZus{}\PYGZus{}getattr\PYGZus{}\PYGZus{}}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{key}\PYG{p}{:} \PYG{n+nb}{str}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:}
\PYG{k}{if} \PYG{o+ow}{not} \PYG{n}{key}\PYG{o}{.}\PYG{n}{startswith}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}\PYGZus{}\PYGZdq{}}\PYG{p}{):}
\PYG{k}{raise} \PYG{n}{wandb}\PYG{o}{.}\PYG{n}{Error}\PYG{p}{(}\PYG{l+s+sa}{f}\PYG{l+s+s2}{\PYGZdq{}...\PYGZdq{}}\PYG{p}{)}
\PYG{k}{else}\PYG{p}{:}
\PYG{k}{raise} \PYG{n+ne}{AttributeError}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{Car} \PYG{o}{=} \PYG{n}{TypeVar}\PYG{p}{(}\PYG{l+s+s1}{\PYGZsq{}Car\PYGZsq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}\PYGZsh{} car is unbounded}
\PYG{n}{Traffic} \PYG{o}{=} \PYG{n}{Union}\PYG{p}{[}\PYG{n}{Car}\PYG{p}{,} \PYG{n}{List}\PYG{p}{[}\PYG{l+s+s1}{\PYGZsq{}Traffic\PYGZsq{}}\PYG{p}{]]}

\PYG{k}{class} \PYG{n+nc}{CarObj}\PYG{p}{:}
\PYG{k}{pass}

\PYG{k}{def} \PYG{n+nf}{count\PYGZus{}cars}\PYG{p}{(}\PYG{n}{x}\PYG{p}{:} \PYG{n}{Traffic}\PYG{p}{,} \PYG{n}{car}\PYG{p}{:} \PYG{n}{Car}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{if} \PYG{n+nb}{isinstance}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{List}\PYG{p}{):}
\PYG{n}{x}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{car}\PYG{p}{)}
\PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{x}\PYG{p}{)}

\PYG{n}{count\PYGZus{}cars}\PYG{p}{([}\PYG{n}{CarObj}\PYG{p}{(),} \PYG{n}{CarObj}\PYG{p}{()],} \PYG{l+m+mi}{5}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}mypy: ok}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{validate\PYGZus{}stat}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable} \PYG{o}{|} \PYG{k+kc}{None}\PYG{p}{:}

\PYG{n+nd}{@wraps}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{wrapper}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{:} \PYG{n+nb}{str} \PYG{o}{|} \PYG{k+kc}{None} \PYG{o}{=} \PYG{k+kc}{None}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable} \PYG{o}{|} \PYG{k+kc}{None}\PYG{p}{:}
\PYG{k}{try}\PYG{p}{:}
\PYG{n}{stat} \PYG{o}{=} \PYG{n}{stat\PYGZus{}func}\PYG{p}{(}\PYG{n}{stat}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{fn}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)}
\PYG{k}{except} \PYG{n}{InvalidStats}\PYG{p}{:}
\PYG{n}{log}\PYG{o}{.}\PYG{n}{exception}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Invalid stat name: }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{.\PYGZdq{}}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{)}

\PYG{k}{return} \PYG{n}{wrapper}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{count\PYGZus{}cars}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{class} \PYG{n+nc}{Shape}\PYG{p}{:}
\PYG{k}{def} \PYG{n+nf}{move}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{dist}\PYG{p}{:} \PYG{n+nb}{int}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Any}\PYG{p}{:} \PYG{c+c1}{\PYGZsh{} imprecise return type, Self is better}
\PYG{n+nb+bp}{self}\PYG{o}{.}\PYG{n}{position} \PYG{o}{+=} \PYG{n}{dist}
\PYG{k}{return} \PYG{n+nb+bp}{self}

\PYG{k}{class} \PYG{n+nc}{Circle}\PYG{p}{(}\PYG{n}{Shape}\PYG{p}{):}
\PYG{k}{pass}

\PYG{n}{Circle}\PYG{p}{()}\PYG{o}{.}\PYG{n}{move}\PYG{p}{(}\PYG{l+m+mi}{4}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{eq}\PYG{p}{(}\PYG{n}{a}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{,} \PYG{n}{b}\PYG{p}{:} \PYG{n}{Any}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{bool}\PYG{p}{:}
\PYG{k}{return} \PYG{n}{a} \PYG{o}{==} \PYG{n}{b}

\PYG{n}{eq}\PYG{p}{(}\PYG{l+s+sa}{b}\PYG{l+s+s1}{\PYGZsq{}b\PYGZsq{}}\PYG{p}{,} \PYG{l+s+sa}{u}\PYG{l+s+s1}{\PYGZsq{}u\PYGZsq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{}mypy: ok}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{validate\PYGZus{}stat}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable} \PYG{o}{|} \PYG{k+kc}{None}\PYG{p}{:}

\PYG{n+nd}{@wraps}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{wrapper}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{:} \PYG{n+nb}{str} \PYG{o}{|} \PYG{k+kc}{None} \PYG{o}{=} \PYG{k+kc}{None}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable} \PYG{o}{|} \PYG{k+kc}{None}\PYG{p}{:}
\PYG{k}{try}\PYG{p}{:}
\PYG{k}{if} \PYG{n}{stat} \PYG{o+ow}{is} \PYG{o+ow}{not} \PYG{k+kc}{None}\PYG{p}{:}
\PYG{n}{stat} \PYG{o}{=} \PYG{n}{stat\PYGZus{}func}\PYG{p}{(}\PYG{n}{stat}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{fn}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)}
\PYG{k}{except} \PYG{n}{InvalidStats}\PYG{p}{:}
\PYG{n}{log}\PYG{o}{.}\PYG{n}{exception}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Invalid stat name: }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{.\PYGZdq{}}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{)}

\PYG{k}{return} \PYG{n}{wrapper}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{\PYGZus{}count\PYGZus{}parameters}\PYG{p}{(}\PYG{n}{func}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{[}\PYG{n}{Any}\PYG{p}{,} \PYG{n}{Any}\PYG{p}{])} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n+nb}{int}\PYG{p}{:}
\PYG{k}{return} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{signature}\PYG{p}{(}\PYG{n}{func}\PYG{p}{)}\PYG{o}{.}\PYG{n}{parameters}\PYG{p}{)}
\end{Verbatim}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{validate\PYGZus{}stat}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{:} \PYG{n}{Callable}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable}\PYG{p}{:}

\PYG{n+nd}{@wraps}\PYG{p}{(}\PYG{n}{fn}\PYG{p}{)}
\PYG{k}{def} \PYG{n+nf}{wrapper}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{:} \PYG{n+nb}{str} \PYG{o}{|} \PYG{k+kc}{None} \PYG{o}{=} \PYG{k+kc}{None}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)} \PYG{o}{\PYGZhy{}\PYGZgt{}} \PYG{n}{Callable} \PYG{o}{|} \PYG{k+kc}{None}\PYG{p}{:}
\PYG{k}{try}\PYG{p}{:}
\PYG{k}{if} \PYG{n}{stat} \PYG{o+ow}{is} \PYG{o+ow}{not} \PYG{k+kc}{None}\PYG{p}{:}
\PYG{n}{stat\PYGZus{}name\PYGZus{}func} \PYG{o}{=} \PYG{n}{get\PYGZus{}stat\PYGZus{}name\PYGZus{}func}\PYG{p}{()}
\PYG{n}{stat} \PYG{o}{=} \PYG{n}{stat\PYGZus{}name\PYGZus{}func}\PYG{p}{(}\PYG{n}{stat}\PYG{p}{)}
\PYG{k}{return} \PYG{n}{fn}\PYG{p}{(}\PYG{n+nb+bp}{self}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{,} \PYG{o}{*}\PYG{n}{args}\PYG{p}{,} \PYG{o}{**}\PYG{n}{kwargs}\PYG{p}{)}
\PYG{k}{except} \PYG{n}{InvalidStatsNameException}\PYG{p}{:}
\PYG{n}{log}\PYG{o}{.}\PYG{n}{exception}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Invalid stat name: }\PYG{l+s+si}{\PYGZpc{}s}\PYG{l+s+s2}{.\PYGZdq{}}\PYG{p}{,} \PYG{n}{stat}\PYG{p}{)}
\PYG{k}{return} \PYG{k+kc}{None}

\PYG{k}{return} \PYG{n}{wrapper}
\end{Verbatim}
Loading