Skip to content

Commit

Permalink
Keep the prior behavior of overwriting File.page (#3381)
Browse files Browse the repository at this point in the history
unless the page value is a *strict* subclass of Page
  • Loading branch information
oprypin committed Sep 10, 2023
1 parent 3db7b8c commit 759e1e3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mkdocs/structure/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,22 @@ def _data_to_navigation(data, files: Files, config: MkDocsConfig):
f"A reference to '{file.src_path}' is included in the 'nav' "
"configuration, but this file is excluded from the built site.",
)
if file.page is not None:
if not isinstance(file.page, Page):
page = file.page
if page is not None:
if isinstance(page, Page):
if type(page) is not Page: # Strict subclass
return page
warnings.warn(
"A plugin has set File.page to an instance of Page and it got overwritten. "
"The behavior of this will change in MkDocs 1.6.",
DeprecationWarning,
)
else:
warnings.warn( # type: ignore[unreachable]
"File.page should not be set to any type other than Page", DeprecationWarning
"A plugin has set File.page to a type other than Page. "
"This will be an error in MkDocs 1.6.",
DeprecationWarning,
)
return file.page
return Page(title, file, config)
return Link(title, path)

Expand Down

0 comments on commit 759e1e3

Please sign in to comment.