• bitcoinBitcoin(BTC)$80,088.00-0.71%
  • ethereumEthereum(ETH)$2,320.19-1.56%
  • tetherTether(USDT)$1.000.02%
  • binancecoinBNB(BNB)$741.37-0.66%
  • rippleXRP(XRP)$1.29-1.30%
  • usd-coinUSDC(USDC)$1.000.02%
  • solanaSolana(SOL)$101.19-0.95%
  • tronTRON(TRX)$0.3299060.40%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.06-0.70%
  • zcashZcash(ZEC)$1,205.61-0.22%
  • HyperliquidHyperliquid(HYPE)$76.28-0.25%
  • dogecoinDogecoin(DOGE)$0.077062-0.35%
  • moneroMonero(XMR)$589.72-3.19%
  • USDSUSDS(USDS)$1.000.01%
  • whitebitWhiteBIT Coin(WBT)$77.13-0.83%
  • chainlinkChainlink(LINK)$11.43-0.51%
  • leo-tokenLEO Token(LEO)$9.040.00%
  • cardanoCardano(ADA)$0.204287-1.30%
  • stellarStellar(XLM)$0.169157-1.22%
  • RainRain(RAIN)$0.0083532.12%
  • nearNEAR Protocol(NEAR)$4.521.13%
  • bitcoin-cashBitcoin Cash(BCH)$281.491.84%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • daiDai(DAI)$1.000.01%
  • litecoinLitecoin(LTC)$56.540.07%
  • uniswapUniswap(UNI)$6.951.89%
  • CantonCanton(CC)$0.1014910.79%
  • avalanche-2Avalanche(AVAX)$8.89-0.27%
  • USD1USD1(USD1)$1.00-0.01%
  • suiSui(SUI)$0.92-1.04%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.23-0.64%
  • hedera-hashgraphHedera(HBAR)$0.077238-0.38%
  • tether-goldTether Gold(XAUT)$4,011.990.48%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • shiba-inuShiba Inu(SHIB)$0.000005-0.98%
  • BittensorBittensor(TAO)$251.510.37%
  • quant-networkQuant(QNT)$193.715.17%
  • EthenaEthena(ENA)$0.2079127.25%
  • crypto-com-chainCronos(CRO)$0.053893-2.11%
  • BitwayBitway(BTW)$1.67-3.17%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • Circle USYCCircle USYC(USYC)$1.140.00%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.04%
  • okbOKB(OKB)$108.400.33%
  • MemeCoreMemeCore(M)$0.998.83%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • aaveAave(AAVE)$135.36-1.39%
  • OndoOndo(ONDO)$0.406834-0.33%
  • Pump.funPump.fun(PUMP)$0.004197-1.59%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

A Coding Implementation on Pyright Type Checking Covering Generics, Protocols, Strict Mode, Type Narrowing, and Modern Python Typing

April 30, 2026
in AI & Technology
Reading Time: 2 mins read
A A
A Coding Implementation on Pyright Type Checking Covering Generics, Protocols, Strict Mode, Type Narrowing, and Modern Python Typing
ShareShareShareShareShare
print("=" * 62)
print("SECTION 9 · pyrightconfig.json")
print("=" * 62)


config = {
   "include": ["src"],
   "exclude": ["**/__pycache__"],
   "pythonVersion": "3.11",
   "typeCheckingMode": "strict",
   "reportMissingImports": "error",
   "reportMissingTypeStubs": "warning",
   "reportUnknownVariableType": "warning",
   "reportUnknownMemberType": "warning",
   "reportUnnecessaryTypeIgnoreComment": "warning",
}
cfg_path = os.path.join(WORK, "pyrightconfig.json")
with open(cfg_path, "w") as f:
   json.dump(config, f, indent=2)
print(f"Written: {cfg_path}")
print(json.dumps(config, indent=2))
print()


print("=" * 62)
print("SECTION 10 · Self, TypeAlias, NewType")
print("=" * 62)


write("s10_modern_types.py", """
   from typing import Self, TypeAlias, NewType


   class Query:
       def __init__(self) -> None:
           self._filters: list[str] = []


       def where(self, cond: str) -> Self:
           self._filters.append(cond)
           return self


       def build(self) -> str:
           return " AND ".join(self._filters)


   class AdvancedQuery(Query):
       def order_by(self, col: str) -> Self:
           return self


   q = AdvancedQuery().where("age > 18").order_by("name")
   reveal_type(q)


   Vector: TypeAlias = list[float]
   Matrix: TypeAlias = list[Vector]


   def dot(a: Vector, b: Vector) -> float:
       return sum(x * y for x, y in zip(a, b))


   v1: Vector = [1.0, 2.0, 3.0]
   v2: Vector = [4.0, 5.0, 6.0]
   dot(v1, v2)
   dot(v1, [1, 2, 3])


   UserId   = NewType("UserId", int)
   OrderId  = NewType("OrderId", int)


   def get_user(uid: UserId) -> str:
       return f"user_{uid}"


   uid = UserId(42)
   oid = OrderId(99)


   get_user(uid)
   get_user(oid)
   get_user(42)
""")


print("→ s10_modern_types.py:")
run_pyright("s10_modern_types.py")


print("=" * 62)
print("SECTION 11 · reveal_type() & type: ignore")
print("=" * 62)


write("s11_reveal_ignore.py", """
   from typing import Any


   values = [1, "two", 3.0]
   reveal_type(values)


   def mystery(x: Any) -> Any:
       return x


   r = mystery(42)
   reveal_type(r)


   bad: int = "oops"
   bad2: int = "also bad"  # type: ignore[assignment]
""")


print("→ s11_reveal_ignore.py:")
run_pyright("s11_reveal_ignore.py")


print("=" * 62)
print("TUTORIAL COMPLETE")
print("=" * 62)
print("""
Topics covered
──────────────
1  Basic annotations & inference
2  Optional / Union / PEP 604 syntax
3  Type narrowing (isinstance, guards, TypeGuard, match)
4  Generics — TypeVar, Generic, ParamSpec
5  Protocols & structural subtyping
6  TypedDict, dataclasses, NamedTuple
7  Literal, Final, @overload
8  Strict mode
9  pyrightconfig.json
10  Self, TypeAlias, NewType
11  reveal_type() & type: ignore


All source files written to: /tmp/pyright_tutorial/
""")

Credit: Source link

YOU MAY ALSO LIKE

Which Screenless Fitness Tracker Is Better For You?

Can You Run Regular Ethernet Cables Outside?

ShareTweetSendSharePin

Related Posts

Which Screenless Fitness Tracker Is Better For You?
AI & Technology

Which Screenless Fitness Tracker Is Better For You?

October 26, 2026
Can You Run Regular Ethernet Cables Outside?
AI & Technology

Can You Run Regular Ethernet Cables Outside?

October 26, 2026
Why Google Chrome Is Always Using So Much RAM
AI & Technology

Why Google Chrome Is Always Using So Much RAM

October 25, 2026
Nanbeige Releases Nanbeige4.3-33B, a 33B Open Agentic Coding Model
AI & Technology

Nanbeige Releases Nanbeige4.3-33B, a 33B Open Agentic Coding Model

October 25, 2026
Next Post
Claude Code, Copilot and Codex all got hacked. Every attacker went for the credential, not the model.

Claude Code, Copilot and Codex all got hacked. Every attacker went for the credential, not the model.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Interest payments on America’s  trillion debt eats up a huge piece of the budget

Interest payments on America’s $40 trillion debt eats up a huge piece of the budget

October 21, 2026
OpenAI Acquires Orchestra Bio to Expand Rosalind Life Sciences Tools – Unite.AI

OpenAI Acquires Orchestra Bio to Expand Rosalind Life Sciences Tools – Unite.AI

October 20, 2026
Multiple children injured in Oregon school shooting

Multiple children injured in Oregon school shooting

October 24, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!