Open
Conversation
0ae6d77 to
d875e72
Compare
d875e72 to
871484f
Compare
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.
Always fetch namespace from API
Summary
Fix the
nsattribute inWikipediaPageandAsyncWikipediaPageso that it correctly fetches the namespace from the API, similar to howpageidis handled. Previously,nswould return the initial value set during object construction, but after an API call (likesummary), it should reflect the correct namespace from the API response.Problem
When creating a page for a category like
c = wiki.page("Category:foo"), thec.nswould initially return0, but afterc.summaryit should correctly return14(the category namespace). The namespace attribute was not being dynamically resolved and updated when API calls were made.Solution
Key Changes
nsandnamespacefetch from API calls likepageidnsandnamespaceproperties in both sync and async classes that trigger API calls when needednsandnamespaceproperties fromBaseWikipediaPage_missing_pageidto accessnsdirectly from_attributesto avoid recursionnamespaceproperty usensproperty to eliminate code duplicationImplementation Details
nsproperty triggersself._fetch("info")when needednsproperty returns a coroutine that handles API callsnsvalues without triggering additional API callsFiles Changed
wikipediaapi/_base_wikipedia_page.py- Updated ATTRIBUTES_MAPPING, removed static propertieswikipediaapi/wikipedia_page.py- Added lazy-loadingnsandnamespacepropertieswikipediaapi/async_wikipedia_page.py- Added awaitable lazy-loadingnsandnamespacepropertieswikipediaapi/_resources/base_wikipedia_resource.py- Fixed recursion in_missing_pageidtests/mock_data.py- Added mock data for namespace teststests/namespace_behavior_test.py- Added 6 comprehensive sync teststests/async_namespace_behavior_test.py- Added 6 comprehensive async teststests/test_sync_async_symmetry.py- Updated symmetry test for new awaitable behaviorTesting
Test Coverage
Test Results
Verification
Benefits
nsbehavior matchespageidand other lazy-loaded attributesQuality Assurance
This change ensures that the namespace attribute behaves consistently with other API-fetched attributes while maintaining full backward compatibility and excellent performance characteristics.
Fixes issue #512