Skip to content

Separate finalization from runtime concerns and introduce FinalizedAppConfig.#2756

Merged
freakboy3742 merged 1 commit intobeeware:mainfrom
filiplajszczak:typing/finalize-runtime-attrs
Mar 24, 2026
Merged

Separate finalization from runtime concerns and introduce FinalizedAppConfig.#2756
freakboy3742 merged 1 commit intobeeware:mainfrom
filiplajszczak:typing/finalize-runtime-attrs

Conversation

@filiplajszczak
Copy link
Copy Markdown
Contributor

finalize() previously mixed two concerns: platform configuration (finalize_app_config) and runtime mode setup (test_mode, debugger). This change moves runtime attributes to callers, so finalize() only handles host/tool verification and app config finalization.

With that separation in place, the __draft__ magic attribute is replaced by a real class: FinalizedAppConfig. Unfinalized apps are AppConfig, finalized ones become FinalizedAppConfig. This would give the type checker a concrete type to track finalization state, replacing hasattr/delattr with isinstance.

Groundwork for typing app finalization (Refs #2739).

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

finalize_app_config() now returns a FinalizedAppConfig constructed
from the original AppConfig. Runtime attributes (test_mode, debugger,
debugger_host, debugger_port) are constructor parameters, guaranteed
to exist at construction time. Platform overrides forward **kwargs
to super() which constructs the object.

AppConfig gains __eq__ and __hash__ based on app_name so that caches
keyed by app objects (like _briefcase_toml and app_tools) work
correctly across the identity change from AppConfig to
FinalizedAppConfig.

Replaces the __draft__ attribute with an isinstance check.

Refs beeware#2739.
@filiplajszczak filiplajszczak force-pushed the typing/finalize-runtime-attrs branch from f9defcf to 529b9de Compare March 20, 2026 16:37
Comment on lines 788 to +789
finalized[app.app_name] = app
self.apps.update(finalized)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need finalized at all here? Can we cache finalized apps directly into self.apps?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered on the upstream discussion - this is needed to avoid modification during iteration. This likely isn't a big problem as we're not adding new keys, but better to be safe.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This all makes sense; thanks!

@freakboy3742 freakboy3742 merged commit d0fa000 into beeware:main Mar 24, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants