Bugfix Config.from_object on Config instances (closes #244)#355
Open
jbbqqf wants to merge 1 commit into
Open
Conversation
`Config.from_object` iterates `dir(instance)` and reads every attribute,
which raises `AttributeError: property 'cert_reqs' of 'Config' object has
no getter` when the instance is a `Config()` itself, because
`cert_reqs = property(None, set_cert_reqs)` is intentionally write-only
to deprecate the name.
Skip names whose getter raises AttributeError so that
hypercorn --config python:my_module.config
is usable when the module exposes a populated `Config` instance.
Closes pgjones#244.
TomiBelan
suggested changes
May 24, 2026
TomiBelan
left a comment
There was a problem hiding this comment.
This feels very unnecessarily complicated. Wouldn't it be easier and more reliable to just add this?
if isinstance(instance, cls):
return instanceNote: I am a random passerby. My "request changes" is not official. You can decide to ignore it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Config.from_objectraisesAttributeError: property 'cert_reqs' of 'Config' object has no getterwhen handed a populatedConfig()instance — i.e. when a user runswith
my_module.config = Config(); my_module.config.bind = "...". This is the documented use case in thefrom_objectdocstring.Root cause:
from_objectiteratesdir(instance)and callsgetattron every name, butcert_reqsis intentionally a write-only property (the deprecation alias forverify_mode). Thegetattrraises before the dict-comprehension can decide what to do.Fix: skip names whose getter raises
AttributeError. The deprecation alias is preserved (it still works when set via attribute write), but no longer crashes the loader.Fixes #244.
Changes
src/hypercorn/config.py— convertfrom_object's dict comprehension to a loop that swallowsAttributeError; comment cites the issue.tests/test_config.py—test_config_from_object_accepts_config_instanceround-trips a populatedConfig()and asserts the values survive.Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
The new regression test fails on
origin/mainwith the exactAttributeErrorcited in #244 and passes on the fix branch.Edge cases
from_object("module")test_config_from_object(existing)Config()instance (the bug)c = Config(); c.bind = [...]; from_object(c)test_config_from_object_accepts_config_instance(new)@propertywrite-onlycert_reqsis exactly thisfrom_object(...)on a module that importsososskipped (unchanged)isinstance(value, ModuleType)checkRisk / blast radius
Single function, single behavioural change: previously-unreachable code paths now reach
from_mapping. Nothing in the project's own test suite regressed (197 / 197). The only observable difference for existing users is thatfrom_objectnow tolerates write-only properties — that cannot break a working caller.PR drafted with assistance from Claude Code (Anthropic). The change was reviewed manually against hypercorn's source. The reproducer block above is the one I used during development; reviewers can paste it verbatim.