Urgent.News

What's breaking now, across hundreds of outlets.

Tech

My Framework Said Any: How a Pyrefly Error Led Me to Fix Typing in SwiftPY

I build SwiftPY , a Python web framework with an async Active Record ORM. Last week I opened one of my own repositories in VS Code and saw this: class DocRepository : model = Doc async def get_doc ( self , doc_id : int ) -> Doc : doc = await self . model . where ( "is_active" , True ) . with_ ( "group" ) . where ( "id" , doc_id ) . first ( ) if not doc : raise NotFoundError ( "Doc not found" )…

I built SwiftPY, an async Active Record ORM-based Python web framework. While working on a repository, I encountered an error stating that the framework returned Any instead of the expected "Doc" type. This error occurred despite the code running correctly and passing tests. The issue stemmed from the type chain having gaps, with certain method calls lacking return annotations, causing the checker to assign Unknown to the subsequent results.

SwiftPY addressed this in version 0.3.8 by carrying the concrete model type through the whole query chain, from ModelQueryBuilder[T] to SingleRelationshipQueryBuilder[T]. This provided developers with a seamless typing experience without the need for explicit annotations.

A secondary issue arose from a global setting in Pyrefly that allowed missing imports to pass silently, leading to the framework returning Unknown even when the code was valid. This occurred frequently in Docker-based workflows where the interpreter lacked the required framework. The fix in version 0.3.9 added per-package overrides to handle the specific libraries with missing type information, resulting in clear error messages when the interpreter lacked the necessary framework, such as "[missing-import] Could not find import of `swiftpy`".

The implementation of these fixes in SwiftPY alleviated the previously encountered issues, ensuring that type errors were now accurately reported and easily identifiable. This improvement not only benefited the developer experience but also integrated a robust CI process to catch such bugs early in the development cycle.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

The message that retried hundreds of times: a retry loop with no exit

I'm Eric Gitangu. I work on backend systems for a mobility/fintech platform. This is the story of one text message that was retried hundreds of times, and what it took to teach the code to take no for…

  • Retry loop with no exit led to hundreds of SMS message retries
  • Three small decisions caused the issue: no catch, error thrown, progress saved prematurely
  • Catch per recipient, exponential backoff, and "not before" stamp resolved the problem

Test browser profile isolation after attaching Playwright over CDP

When Playwright attaches to Chrome over CDP, it can see the browser's existing context. A script that opens a new tab there inherits that context's first-party storage for the origin.

  • Playwright can inspect browser contexts via CDP
  • New tab inherits context's first-party storage
  • Separate contexts prevent request collisions

Exporting Qwen2-VL the official way: 4 dead ends and 1 error that doesn't exist on the internet

You do everything by the book. The vendor's own toolkit, the vendor's own guide, a model the toolkit claims to support. Three hundred and seventy-one build steps scroll past, all green — and then it…

  • Error "mropesection" persists across hardware and configurations
  • Qwen3-VL-2B optimization completes successfully without error
  • Qwen2-VL export issue unique to older model, no public fix

More from Friday 27 November →