That stores the expression passed to sorted(...) into "iterable".
If you find yourself in code full of isinstance and attribute checks, consider match-case.
That stores the expression passed to sorted(...) into "iterable".
If you find yourself in code full of isinstance and attribute checks, consider match-case.
Match objects by their type and attributes with match-case. 🧵
A class pattern checks an object's type (like isinstance does) and the values of its attributes, capturing attributes into variables.
#Python #DailyPythonTip
Match objects by their type and attributes with match-case. 🧵
A class pattern checks an object's type (like isinstance does) and the values of its attributes, capturing attributes into variables.
#Python #DailyPythonTip
It only checks that the methods exist, not their signatures. For full checks at runtime, the tutorial points to beartype or typeguard.
It only checks that the methods exist, not their signatures. For full checks at runtime, the tutorial points to beartype or typeguard.
nm=lambda v:v.get('name') if isinstance(v,dict) else v if isinstance(v,str) else None
nm=lambda v:v.get('name') if isinstance(v,dict) else v if isinstance(v,str) else None
clk=lambda ms:' (%02d:%02d)'%(ms//60000,ms//1000%60) if isinstance(ms,int) else ''
clk=lambda ms:' (%02d:%02d)'%(ms//60000,ms//1000%60) if isinstance(ms,int) else ''
1. Over-defensive coding (adding ??, .get(), isinstance, try/except pass, or extra optional params that violate Factory's "no silent fallbacks / no dead options" rule).
1. Over-defensive coding (adding ??, .get(), isinstance, try/except pass, or extra optional params that violate Factory's "no silent fallbacks / no dead options" rule).
Read more 👉 pym.dev/goose-typing/
#Python
Read more 👉 pym.dev/goose-typing/
#Python
Prefer isinstance over type for type checking. 🧵
Do this:
isinstance(value, int)
Not this:
type(value) == int
Unlike comparing with type(...), using isinstance respects inheritance.
#Python #DailyPythonTip
Prefer isinstance over type for type checking. 🧵
Do this:
isinstance(value, int)
Not this:
type(value) == int
Unlike comparing with type(...), using isinstance respects inheritance.
#Python #DailyPythonTip
>>> isinstance(4.5, (int, float))
True
>>> isinstance("4.5", (int, float))
False
>>> isinstance(4.5, (int, float))
True
>>> isinstance("4.5", (int, float))
False
>>> from collections import Counter
>>> counts = Counter("hello")
>>> isinstance(counts, dict)
True
>>> type(counts) == dict
False
Checking with type means nobody can inherit from your class without breaking your type check.
>>> from collections import Counter
>>> counts = Counter("hello")
>>> isinstance(counts, dict)
True
>>> type(counts) == dict
False
Checking with type means nobody can inherit from your class without breaking your type check.
>>> from collections.abc import Iterable
>>> isinstance("hello", Iterable)
True
That's how I'd recommend asking "is this object iterable?"
bsky.app/profile/trey...
>>> from collections.abc import Iterable
>>> isinstance("hello", Iterable)
True
That's how I'd recommend asking "is this object iterable?"
bsky.app/profile/trey...
Read more 👉 pym.dev/goose-typing/
#Python
Read more 👉 pym.dev/goose-typing/
#Python
Z={"JPY","KRW","VND","CLP","ISK","UGX","PYG"}
def norm(p):
a=p.get("amount");c=str(p.get("currency","")).upper()
if not isinstance(a,(int,float)):return {"valid":False,"currency":c}
if len(c)!=3 or not c.isalpha():return {"valid":False,"currency":c}
Z={"JPY","KRW","VND","CLP","ISK","UGX","PYG"}
def norm(p):
a=p.get("amount");c=str(p.get("currency","")).upper()
if not isinstance(a,(int,float)):return {"valid":False,"currency":c}
if len(c)!=3 or not c.isalpha():return {"valid":False,"currency":c}
CVE ID : CVE-2026-76850
Published : Aug. 19, 2026, 10:17 p.m. | 14 minutes ago
Description : LMDeploy deserializes disaggregated-serving peer mes...
CVE ID : CVE-2026-76850
Published : Aug. 19, 2026, 10:17 p.m. | 14 minutes ago
Description : LMDeploy deserializes disaggregated-serving peer mes...
Read more 👉 pym.dev/goose-typing/
#Python
Read more 👉 pym.dev/goose-typing/
#Python
print("\n📊 MODEL EVALUATION\n") eval_results = trainer.evaluate() print(" Evaluation Results:") for key, value in eval_results.items(): if isinstance(value, float): print(f"…
print("\n📊 MODEL EVALUATION\n") eval_results = trainer.evaluate() print(" Evaluation Results:") for key, value in eval_results.items(): if isinstance(value, float): print(f"…